动作脚本函数可以找出自己的名字吗? [英] can an actionscript function find out its own name?
本文介绍了动作脚本函数可以找出自己的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
鉴于以下内容
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()
有关该技术的更多信息,请访问 Alex 的网站:
More information about the technique can be found at Alex's site:
http://blogs.adobe.com/aharui/2007/10/debugging_tricks.html
这篇关于动作脚本函数可以找出自己的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文