Guest
Public paste!

ejot

By: a guest | Jul 7th, 2008 | Syntax: ActionScript | Size: 1.20 KB | Hits: 43 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. package
  2. {
  3.         public class InterestingClass
  4.         {
  5.                 protected static function processStacktrace():Object {
  6.                         var inspected:Object = new Object();
  7.                         var inspectionPattern:RegExp = new RegExp(".*at .*\\/(.*)\\(\\)\\[.*\\/(.*)\\..*\\]");
  8.                                                
  9.                         var stacktrace:String = new Error().getStackTrace();
  10.                         var called:String = stacktrace.split("\n")[2];
  11.                         var calling:String = stacktrace.split("\n")[3];
  12.                        
  13.                         inspected["called"] = {"cls":called.match(inspectionPattern)[2], "method":called.match(inspectionPattern)[1]};
  14.                         inspected["calling"] = {"cls":calling.match(inspectionPattern)[2], "method":calling.match(inspectionPattern)[1]};
  15.                         return inspected;
  16.                 }
  17.                
  18.                 protected function doOutput(inspected:Object):void {
  19.                         trace("I am in", inspected.called.method, "of", inspected.called.cls, "and was called from", inspected.calling.method, "of", inspected.calling.cls);
  20.                 }
  21.                
  22.                 public function method1():String {
  23.                         var inspected:Object = processStacktrace();
  24.                         doOutput(inspected);
  25.                         return "I am method1";
  26.                 }
  27.                
  28.                 public function method2(value:String):String {
  29.                         var inspected:Object = processStacktrace();
  30.                         doOutput(inspected);
  31.                         return "You told me: " + value;
  32.                 }
  33.         }
  34. }