« Drag and drop between Tree and List | Main | A designer point of view on Adobe Max Milan »

Actionscript debug tips: who called my actionscript method?

A good debug tip when you program in actionscript is to know who and when has called your method. This can be done by generating an error using the "throw new Error()" command inside the traced method. Through a custom error exception we can trace the stack and see the iter of the entire process.

So let's create the method that will invoke the tracing method of the stack:

private function methodToCall() : void
{
calledMethod();
}

Now we have to create the method that trace the stack

private function calledMethod() : void
{
try
{
throw new Error( "my error" );
}
catch ( e:Error )
{
trace( e.getStackTrace() );
}
}

This will be the result, showing the invocation path:

Error: my error
at myproject/calledMethod()[G:\yourpath.mxml:18]
at myprojec/methodToCall()[G:\yourpath.mxml:11]
at myprojec/Button1_click()[G:\yourpath.mxml:4]

For further reference, please consult the documentation of the Error class, on the Adobe site:
LiveDocs Error Class

TrackBack

TrackBack URL for this entry:
http://blog.comtaste.com/mt-tb.cgi/68

Comments (3)

Great tip. Thanks!

Imtiyaz Basha:

How can we have the reference of the function who called me ????

Anonymous:

Thank you, still very helpful in 2010 ;-)

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on November 29, 2008 5:52 PM.

The previous post in this blog was Drag and drop between Tree and List.

The next post in this blog is A designer point of view on Adobe Max Milan.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33