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
Comments (3)
Great tip. Thanks!
Posted by Justin_P | November 29, 2008 9:17 PM
Posted on November 29, 2008 21:17
How can we have the reference of the function who called me ????
Posted by Imtiyaz Basha | May 6, 2009 2:34 PM
Posted on May 6, 2009 14:34
Thank you, still very helpful in 2010 ;-)
Posted by Anonymous | March 18, 2010 11:04 AM
Posted on March 18, 2010 11:04