Using the built-in Flash trace method

To use the Debug Flash Players built-in trace method instead of the TextField used by Haxe I found this short snippet very useful:

#if (flash9 || flash10)
haxe.Log.trace = function(v,?pos) { untyped __global__["trace"](pos.className+"#"+pos.methodName+"("+pos.lineNumber+"):",v); }
#elseif flash
haxe.Log.trace = function(v,?pos) { flash.Lib.trace(pos.className+"#"+pos.methodName+"("+pos.lineNumber+"): "+v); }
#end

So the output of this:

class Example {
    static function main() {
        #if (flash9 || flash10)
        haxe.Log.trace = function(v,?pos) { untyped __global__["trace"](pos.className+"#"+pos.methodName+"("+pos.lineNumber+"):",v); }
        #elseif flash
        haxe.Log.trace = function(v,?pos) { flash.Lib.trace(pos.className+"#"+pos.methodName+"("+pos.lineNumber+"): "+v); }
        #end
        trace( "YEAH!" );
    }
}

Would result in this (in the flashlog.txt):

Example#main(8): YEAH!

After using that snippet all trace statements gets redirected to a flashlog.txt which can be easily "tailed" using this terminal command (in OSX):

tail -f ~/Library/Preferences/Macromedia/Flash\ Player/Logs/flashlog.txt

Please extend this with the similar commands for other operating systems.

version #7942, modified 2010-01-21 16:25:17 by slaskis