在actionscript中是否有行号常量或动态跟踪行号的方法?
actionscript是否有等价物
__LINE__在PHP中?
发布于 2009-07-28 13:23:41
这不是一个常量,但是下面这行代码会给出行号:
trace(">",new Error().getStackTrace().match(/(?<=:)[0-9]*(?=])/g)[0]);PS:只有在调试模式下编译swf时,这才能起作用
发布于 2011-07-05 07:06:45
要使用OXMO456的技巧作为函数,只需使用match结果的索引1(而不是索引0)。下面的代码执行此操作并检查调试功能:
import flash.system.Capabilities;
/**
* Returns the positive line number from which the function is called, if
* available, otherwise returns a negative number.
*/
function lineNumber():int {
var ret:int = -1;
if (Capabilities.isDebugger) {
ret = new Error().getStackTrace().match(/(?<=:)[0-9]*(?=])/g)[1];
}
return ret;
}示例:
trace('line ' + lineNumber() + ' reached!');https://stackoverflow.com/questions/1191393
复制相似问题