可ActionScript函数找到了自己的名字吗? [英] can an actionscript function find out its own name?
本文介绍了可ActionScript函数找到了自己的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面给出
function A(b:Function) { }
如果函数A(),才能确定所传递的参数B的函数的名称?其答案是否有所不同AS2和AS3?
If function A(), can we determine the name of the function being passed in as parameter 'b' ? Does the answer differ for AS2 and AS3 ?
推荐答案
我用下面的:
private function getFunctionName(e:Error):String {
var stackTrace:String = e.getStackTrace(); // entire stack trace
var startIndex:int = stackTrace.indexOf("at ");// start of first line
var endIndex:int = stackTrace.indexOf("()"); // end of function name
return stackTrace.substring(startIndex + 3, endIndex);
}
用法:
private function on_applicationComplete(event:FlexEvent):void {
trace(getFunctionName(new Error());
}
输出: FlexAppName / on_applicationComplete()
Output: FlexAppName/on_applicationComplete()
有关该技术的更多信息,亚历克斯的网站上找到:
More information about the technique can be found at Alex's site:
<一个href="http://blogs.adobe.com/aharui/2007/10/debugging_tricks.html">http://blogs.adobe.com/aharui/2007/10/debugging_tricks.html
这篇关于可ActionScript函数找到了自己的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文