[solved] How to get an array of public variables?

7 posts

Flag Post


For now I do the following:

var typeDescription:XML = describeType(event.data);
var variablesList:Array = (typeDescription..variable.@name as XMLList).toXMLString().split("\n");

It does the trick but the ‘toXMLString().split(“\n”)’ doesn’t look like an optimal way to do it.

Is there a better way?

Thank you.

Flag Post

for (var s:String in (event.data as Object)) {...}
Might do, but also might result in a ton of unwanted variables.

Flag Post

I assume that was your thread/post that got eaten up by the spam filter? (I unhid it, but you can delete it or pm me to delete it if you want)

Flag Post

vesperbot, thanks, but it would yield only dynamic members but not the ones declared like public var something:int.

UnknownGuardian, thanks, but no, I was just using a wrong account to post :)

Flag Post

You could use this if you have the Flex SDK:

Although it also uses describeType internally.

You could also put them in an Array by looping through the XMLList, depending on the data you actually want

Flag Post

for each(var field:XML in xml.variable) a.push(field.@name); is how I’d do it. I don’t think there’s a magic way to turn an XMLList into an array though.

Flag Post

Thanks, guys.