Actionscript object number of properties
问题 How can I get the number of properties in a generic Actionscript Object? (Like Array length) 回答1: You will have to loop over all element to count them: function objectLength(myObject:Object):int { var cnt:int=0; for (var s:String in myObject) cnt++; return cnt; } var o:Object={foo:"hello", bar:"world"}; trace(objectLength(o)); // output 2 回答2: Even shorter code here: var o:Object={foo:"hello",bar:"world",cnt:2}; trace(o.cnt); // output 2; Just remember to update the very last argument in the