Acedia – apathy and laziness in the practice of virtue

I am an admittedly lazy programmer and therefore, i hate doing manual “labour” with regards to coding. A perfect example of manual labour in coding is writing APIs. The toString() function kills me! I like to write my own toString() functions for enhanced debugging, but i couldn’t take it anymore. I’m working on a project in which the one class has 10 public properties and i refused to write a function that would put all 10 in a pretty, indented, explanatory format. So i began digging in the AS3 API and found this beauty…

describeType(value:Object):XML

In AS3, the for..in loop does not enumerate properties and functions declared by a class (thanks to Emmy Huang). What this means is that you cannot create a toString() function like this – which is what i’d hoped to do.

Instead, what you have to do is use the describeType function in your for..in loop instead of using this. However, the describeType function returns an XML layout of your class, so – for example – to enumerate all variables in the XML returned from this function, simply do this:

// enumerate variables in its own class
var variables:XMLList = describeType(this)..variable;

// enumerate variables from outside its class.
var variables:XMLList = describeType(getDefinitionByName(“MyClass”))..variable; 

 

Then, with the variables XMLList, you can loop for all variables in your class, do whatever you like with them, and know deep in your heart that you’re such a lazy fucker :D  

Advertisement

~ by as3fd on October 12, 2008.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.