Archive for March, 2010

AS3 – Looping over properties of a class (property enumeration)

In AS1 & AS2 you could use a loop to enumerate the properties of an Object for introspection. Given that everything in Actionscript extends the Object class I expected that you could do a loop over the properties of a Class. For example if you wanted to do a loop over all the properties in a value object.

//Sample code to trace the properties of an object
var myVO = new MyVO();
for(i in myVO){

However in AS3 this code will not work as expected (assuming that MyVO is not a dynamic class). I’ve come across this a couple of times in the last couple of weeks a yesterday found the solution to it.

There is a new function which gives all the introspection data for classes in AS3 – flash.util.describeType() which returns an XML Object.

//Get an XML description of this class

To do the previous looping over the properties it could be used as follows:

//Get an XML description of this class
//and return the variable types as XMLList with e4x
var varList:XMLList = flash.utils.describeType(myVO)..variable;

for(var i:int; i < varList.length(); i++){
//Show the name and the value
trace(varList[i].@name+’:’+ myVO[varList[i].@name]);

There is one other thing to catch you out though. If you make your variables [Bindable] or use getters & setters they will not show up as “variable”. They will show up instead as “accessor” which is something to be aware of.

Hope it helps.


Convert/Create Java DTO to Action script (AS) Equivalent Remote Class

Hi Friends,

we were having trouble finding java to AS class converter to do my work. There are loads of converter but doesnt do my task.

Thought I might as well write one which serves my purpose of creating Java DTO’s To Action Script equivalent classes.

If you find it usefull let me know. This is in intial stages, let me know if some thing can be improved on.. So that we can take it forowrd

Attaching J2A.air File.

updated V 0.2 >>>


Ranjit Sail