Actionscript debug tips: who called my actionscript method?

来源:互联网 发布:mac 射手 字幕位置 编辑:程序博客网 时间:2024/06/05 20:06

转自:http://blog.comtaste.com/2008/11/how_to_know_who_called_my_acti.html

 

Agood debug tip when you program in actionscript is to know who and whenhas called your method. This can be done by generating an error usingthe "throw new Error()" command inside the traced method. Through acustom error exception we can trace the stack and see the iter of theentire 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

原创粉丝点击