Flex/ActionScript: Making trace() display the method it was called in
the console of my fellow developers. We agreed on making every trace() show
the method it came from, but I am too lazy to do this, this makes it automatic:
1 2 public static function TRACE(s:Object):void { 3 try { 4 throw new Error(); 5 } catch (e:Error) { 6 var stack:String = e.getStackTrace(); 7 var frames:Array = stack.split("\n"); 8 var myFrame:String = String(frames[2]); 9 myFrame = myFrame.replace("\t", ""); 10 11 // "at " can be followed by some part of the package 12 // you don't want to see. E.g., if your code is all in 13 // com.foo.bar, you can put "at com.foo.bar." so as not 14 // to crowd the display 15 myFrame = myFrame.substr("at ".length); 16 myFrame = myFrame.substring(0, myFrame.indexOf("[")); 17 trace(myFrame + ": " + s); 18 } 19 }