View Full Version : Looping through objects?
axiomflash
October 19th, 2007, 02:53 PM
It is easy to loop through an Object or Array's properties with the following:
for(var j:String in myData){
trace(j, myData[j]);
}
But I need to loop through the properties of an unknown object, a sprite for example. How can I loop through a sprite like above and have it trace out all the properties?
alpha: 1
x: 50
y: 40
etc...
kmintmier
October 19th, 2007, 02:58 PM
If you're up for a bit of fun, you could try parsing the XML returned by flash.utils.describeType. Try this:
import flash.display.Sprite;
import flash.utils.describeType;
trace(describeType(new Sprite()));You could, for example, derive a list of accessors and loop through them.
EDIT: If anyone knows an easier way, I'm all ears. This is the only one that comes to mind.
axiomflash
October 19th, 2007, 05:27 PM
I ended up trying this kmintmier, and it worked moderately well. Clever idea.
My goal was to duplicate an existing object (whether that be a TextFormat, Sprite, etc), which is seemingly impossible otherwise. That method is awkward but worked well for duplicating a TextFormat (since most of its properties are strings/numbers), but if I was duplicating a movieclip that had more complex properties it would probably fail.
var a = b;
a.name = "clipAAA";
trace(b.name); //traces"clipAAA"
The above doesn't work because vars 'a' and 'b' share the same memory space. I want to be able to set 'a' to the VALUE of 'b'. Why isn't this possible???? Can anyone explain why AS3 won't let you just duplicate an existing object, or if there is a proper way to go about this?
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.