Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

http://www.hrum.org http://debedb.blogspot.com/

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Flex/ActionScript: Making trace() display the method it was called in

While trace() is useful, its indiscriminate use by me often crowds
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  }
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS