David
David

Reputation: 773

How to trace order of code execution in actionscript?

I'm writing a mobile application in AIR and I often run into the same problem: what is the order of execution? I know that one can determine the order of initialization, creation, etc. for a UI class. I can also put trace statements into the constructor of every class, and do it that way. But that's tedious.

Is there a generic piece of code that will have each class 'announce' itself as it loads? Has anyone written anything like this?

Pseudocode would be something like:

for each var class:Class in application
{
     trace(class.getQualifiedClassName.toString();
}

Thanks.

Edit:

Here's an example. I run MyApp.mxml and I put trace statements on it. The first view is a list which is populated by an array, which comes from a server via xml. But when the app loads, the list is blank. Why? Because of the following order of events, based on trace statements I've inserted manually:

MyApp::viewnavigatorapplication1_intitializeHandler firing
Model::initialize function firing
XMLLoader::going to http://mysite.com/myxml.xml
MyApp::addedToStageHandler running
HomeListView::viewActivateHandler firing
XMLLoader::xmlLoaded

The reason that the list is blank is that the xml is loaded after HomeListView has been activated. So it would be helpful to have a way to get all this info without having to write it in class after class. And note that not all classes are on the displaylist (e.g. Model and XMLLoader).

Upvotes: 2

Views: 287

Answers (2)

Michael Brewer-Davis
Michael Brewer-Davis

Reputation: 14276

Specifying AS3Trace in an mm.cfg file will give the complete firehose of executing functions.

See this blog post for other hidden mm.cfg features, and here is some help getting mm.cfg running in your mobile app.

Upvotes: 2

Majid Laissi
Majid Laissi

Reputation: 19788

Here's something close to what you want:

var numChildren:Number = this.numChildren;
for (var i:int = 0; i < numChildren; i++) {
    var displayObject:DisplayObject = this.getChildAt(i);
    displayObject.addEventListener(FlexEvent.INITIALIZE, function (e:FlexEvent):void {
        trace("child " + displayObject.name +" is initializing" );
    });
    displayObject.addEventListener(FlexEvent.CREATION_COMPLETE, function (e:FlexEvent):void {
        trace("child " + displayObject.name +"'s creation is completed" );
    });                     
}

You need to add it to your main application's initialize event handler.

Upvotes: 0

Related Questions