views:

38

answers:

1

Is it possible to reflect an object in actionscript and get the property names back in the order they are positioned in the class? I have tried the following

var reflectionObject : Object = ObjectUtil.getClassInfo(obj);   
var propsArray : Array = reflectionObject.properties;
(orders alphabetically)

var typeInfo:XML = describeType(obj)
(Not sure what order this is)
+1  A: 

There is little ways of reflecting an object in AS3, but all of them are mentioned on this site.

Both of your ways are correct.

Other ways of doing so include, but are not limited the following, according to insideria:


  • Accessors (Getters/Setters)

    var accessors:XMLList = classAsXML.accessor;
    trace("accessors", accessors.length(), accessors);
    
  • Properties

    var variables:XMLList = classAsXML.variable;
    trace("variables", variables.length(), variables);
    

EDIT: I have revised my answer and I have found the following site that adds up some details about reflection.

EDIT 2: I knew I forgot something here. What jonathanasdf said in his comment is true: there is no way to get the properties in the order defined in a said class.

Christopher Richa
however, you are not going to get them back exactly in the order they were defined in the class. There is no way of doing that, afaik. And there is the .method property too.
jonathanasdf
That is true. Thanks for pointing it out.
Christopher Richa
Thanks. I will just have to add some metadata to my classes to achieve this then? I really like using reflection :) thanks
Chin