// Flash debugging widget // Copyright 2007 Amit J Patel, amitp@cs.stanford.edu // License: MIT (see LICENSE file) package { // Used for debugging output import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFormat; public class Debug extends Sprite { private var txt:TextField; private static var singleton:Debug; public function Debug(parent:Sprite) { // There can be only one!! if (singleton) { // TODO: how to throw an error? } singleton = this; cacheAsBitmap = true; txt = new TextField(); txt.selectable = false; txt.height = 500; // TODO: parent.height; txt.width = 500; // TODO: parent.width; var format:TextFormat = txt.getTextFormat(); format.color = 0x666666; format.font = "_typewriter"; format.size = 9; txt.defaultTextFormat = format; addChild(txt); } public static function trace(...args):void { singleton.txt.appendText("\n" + args.join(" ")); if (singleton.txt.text.length > 10000) { singleton.txt.text = singleton.txt.text.slice(-10000); } singleton.txt.scrollV = singleton.txt.maxScrollV; } } }