One of the nice things about MTASC is it’s TRACE function. Utilizing the -trace compile parameter, you can map the TRACE function written in your ActionScript to a static class method of your choice.
You get an additional 3 parameters passed to your trace:
- Full class package path and name with method
- File name of the class
- line number the TRACE command is at in your class
You can get some really informative and nicely formatted trace messages now. Below is something I whipped up this morning to get it to look cool in Flashout; you can use this with trace too if you don’t use Flashout. Modify the tabs to suit.
static public function coolTrace(str:String, classNameAndMethod:String, fileName:String, lineNumber:Number):Void { var splitClassAndMethod:Array = classNameAndMethod.split("."); var classAndMethod:String = splitClassAndMethod[splitClassAndMethod.length - 1]; var classAndMethodArray:Array = classAndMethod.split("::"); var theClass:String = classAndMethodArray[0]; var theMethod:String = classAndMethodArray[1]; var theString:String = "message: \t" + str + "\n"; theString += "\t\t\tclass: \t\t" + theClass + "\n"; theString += "\t\t\tmethod: \t" + theMethod + "\n"; theString += "\t\t\tfilename: \t" + fileName + "\n"; theString += "\t\t\tline: \t\t" + lineNumber; //trace(theString); Flashout.debug(theString); }
The above, when tested, will give you something alone the lines of this:
Pimp as hell, eh!?
Thanks Kenny for inspiring me to get this to work! Now, if I can just figure out how to make the line # a hyperlink so if you click it, it’ll take you to the line number you clicked on in the correct as file…