Today Creative
Studio: +44 (0)20 7738 7380


Posted by admin on 13th November 2008 in Web Development

There are several packages for debugging and or trace proxying AS3 applications out there. At some point it may be good to concentrate on one and let it become an integral part of your development cycle regardless of project size. I often tend to use the good old trace() in conjunction with the Flash debug player and a tool reading out the flashlog written by it in realtime like the great Firefox plugin “FlashTracer” oder the high performance Socket Server SOS or SOS max of the powerfklasher guys. Very often i feel the need to monitor object data to predict or reflect a certain state of an application. I wrote a class that can be easily hooked in for that. It dumps the structure of custom objects as well as of instances of sealed classes. Since AS3 there is no way to loop over properties of an instance of a non dynamic type with a simple for loop as it was possible in AS2. To overcome this i utilized the reflective and verbose describeType() residing in the flash.utils package. Also the structure of nested objects of the display list can be traced. Its a static class that provides 2 methods: dump() for the direct delegate to trace() and getParsed() for returning the result String. Both method you give the object to be parsed.

Also i implemented a the depth index value to the output since at several times in projects it comes about dealing with sorting or overlapping issues that can be uncovered quickly with that.

Below there is an example tracing the parsing results into a text field of a) a display objecty structure and b) a data object being a webservice request response ( Here to the newly released New Tork Times Movie Reviews API ). The two traces are separated by a hash line.

Code used for the example above:

import de.fascina.utils.ObjectParser;
import com.adobe.serialization.json.JSON;
import flash.display.*;
import flash.text.*;

private function initApp():void
var l:URLLoader = new URLLoader();
var url:String = “”;
var r:URLRequest = new URLRequest( url );
l.load( r );
l.addEventListener( Event.COMPLETE, loadCompleteHandler );

// do a little DisplayObject stack
var holder:Sprite = new Sprite(); = “holder”;
var nested1:Sprite = new Sprite(); = “nested1″;
var txt:TextField = new TextField(); = “txt”;
nested1.addChild( txt );
holder.addChild( new Sprite() );
holder.addChild( nested1 );
holder.addChild( new Sprite() );
t.text = ObjectParser.getParsed( holder );

t.text += “nn###############################################nn”;

private function loadCompleteHandler( event:Event ):void

var l:URLLoader = as URLLoader;
var d:Object = JSON.decode( ) as Object;
var da:Array = d["results"] as Array;
t.text += ObjectParser.getParsed( da );


Get the Source

1 Comment

One Response to ' AS3 ObjectParser '

Subscribe to comments with RSS or TrackBack to ' AS3 ObjectParser '.

  1. Thoughtomatic » AS3 depth sorting of display objects said,

    [...] When it comes to working with structures of Display Objects and depths there is another tool that may come handy. This class, merely an object parser, but with the feature to also trace a nested structure of objects in the display list and showing their depths. Via a public static member SHOW_SHAPES = false we can exclude Shape Objects from being shown since they mostly habe no relevance to the program logic and therefor dont need to be traced. 70e [...]

    on 21st November 2008 at 9:19 am

Post a Comment

Please fill in Name, Mail and Comment text.