Created
April 22, 2013 03:25
-
-
Save lynxerzhang/5432264 to your computer and use it in GitHub Desktop.
inspired from oyvindnordhagen.com' s method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
/** | |
* @see http://www.oyvindnordhagen.com/blog/2010/09/06/quick-as3-tip-find-out-where-a-function-was-called-from/ | |
* | |
* 添加判断方法的类型 | |
* 添加判断swf是否为debug版, 避免getStackTrace返回为空 | |
* @return 返回的字符串格式为 类 --> 方法 --> 具体行数 | |
*/ | |
public function getCaller():String | |
{ | |
var s:String = new Error().getStackTrace(); | |
if (!s || s.search(/.as:[0-9]+]$/gm) == -1) { | |
return "no caller info"; | |
} | |
s = s.split("\n", 3)[2]; | |
var className:String = s.match(/(?<=\\)[a-zA-Z]+(?=\.as)/g)[0]; | |
var funName:String = s.match(/\w+(?=\(\))/g)[0]; | |
var line:Number = s.match(/(?<=as:)\d+(?=\])/g)[0]; | |
var methodType:String; | |
if (s.search(/(?<=\$)(?=\/)/g) != -1) { | |
//是否为静态方法 | |
methodType = "static method"; | |
} | |
else if (s.search(/(?<=global)(?=\/)/g) != -1) { | |
//是否为包级函数 | |
methodType = "global method"; | |
} | |
else { | |
methodType = "instance method"; | |
} | |
return className + "'s " + methodType + " " + funName + " lineAt: " + line; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment