We often had to spend a couple of minutes finding out which class traced something like "hey, it works". With this in mind I came up with the idea to give trace the ability to even show which class was tracing. So we've extended our Debug-Class furthermore (there will be an article about dumping your objects clearly) with a trace-statement. Looks like that:
Actionscript:
-
Debug.Dtrace("hey, it works"):
-
// Output: hey, it works (was called from init() in de/derpunkt/framework/FrameworkView.as)
I'm still messing around with the RegExp but basically it works, so everybody out there needing this class feel free to use it and of course changing it for your purposes.
Actionscript:
-
public static function Dtrace(param:*):void {
-
var pattern:RegExp = /at.*[^)](\/.*())/gim;
-
try {
-
throw new Error();
-
}
-
catch (e:Error) {
-
var result:String = e.getStackTrace().match(pattern)[1];
-
trace(param + " (was called from: " + result.replace(pattern, "$1") + ")");
-
}
-
}



September 13th, 2009
Marvin Blase
Posted in Uncategorized
Tags:
[...] hey, it works (was called from initFramework() in de/derpunkt/framework/FrameworkView.as) hepp! | Beautify Code - Web Development & Actionscript [...]