Lately I’ve been messing around with Flash on devices and in other “new frontiers”. It’s fun, but sometimes getting debugging working is hit or miss. To address this, I wrote an ultra simple class for tracing to a text field. It’s nothing fancy, but that’s the point – it’s simple (~15 lines of code), tiny (~0.5kb), handy (at least for me), and works well, so I thought I’d share.
To use it, simply drop Out.as into your class directory. Set an output text field when your app starts up:
Out.textField = outFld; |
You can also specify a maximum number of characters to retain, so that old traces will be deleted as new ones are added.
Out.maxLength = 1000; |
From anywhere in your application you can call Out.trace(value). This will trace the value normally, append it to the end of your text field, and scroll the text field to the end so that the latest trace is always displayed.
Out.trace("hello"); Out.trace("count: ",count); // supports multiple params |
Finally, if you want to do something more custom, you can override Out.handler to use your own function.
function log(...rest:Array):Boolean { trace("logging: "+rest.join(",")); // ... etc. // only write to text field if first param (ex. priority) is > 1: return rest[0] > 1; // returning false prevents it being written to Out.textField. } Out.handler = log; |
You can download the Out class here. It is licensed under the MIT license.

