ActionScript Property Iteration
May 22, 2008 – 6:00 pmI’m fairly new to ActionScript (3.0) and if I haven’t iterated over the properties of an object in a while, I forget how it.
It, of course, is not in the object APIs - which it totally where you’d expect it to be. Originally there was a “for each” loop, and searching the Net will lead you more likely to that solution. That loop only iterates over dynamic variables (as such an mechanism should imply to you).
Now there is a kind of slapped on utility that will provide XML introspective data of a class.
in flash.utils:
public function describeType(value:*):XML
There are several examples that will show you the E4X that will grab the properties for you, and adding a bit more, this will get them into an array for you:
var description:XML = describeType(entity);
var d2:String = description..accessor.@name.toXMLString();
var accessors:Array = d2.split("\n");
You can then iterate over them.
The XML formatted information is an annoying cop-out to providing actual introspection of classes.