Tracer with textfield トレーサ madflash forked:1favorite:0lines:70license : MIT License modified : 2010-11-01 18:15:18 Embed Tweet //簡易汎用トレーサ //改造するなり拡張なりお好きにどうぞ。 package { import flash.display.Sprite; public class TracerDevelop extends Sprite { //Tracerクラスをnewして使う private var trace:Tracer = new Tracer(); public function TracerDevelop() { //トレーサ用プロパティ設定(TextFieldが持つプロパティと同一) //trace.property(20,20)と同じ trace.property( { x:20, y:20 } ); trace.isDevelop = true; //トレーサを作成 addChild( trace.create ); //ディベロップ用、isDevelopパラメータで切り替えが可能 trace.dev( "Enable when isDevelop status is true." ) //トレースする内容をpushで格納 trace.push("automatic add newline."); trace.push("simple tracer."); //使用例 trace.push("Example:"); trace.push(0,1,2,3,4,"5."); //複数OK //画面出力 trace.show(); } } } /* 以下をコピー&ペーストして下さい */ import flash.system.IME; import flash.display.*; import flash.text.*; class Tracer extends Sprite { public var format:TextFormat; public var txt:TextField; private static const NEWLINE:String = "\n"; private var _log:String = ""; private var _isDev:Boolean = false; public function get create() :TextField { return txt }; //getter public function get log() :String { return _log }; public function get isDevelop() :Boolean { return _isDev }; public function set isDevelop(bool:Boolean) :void { _isDev = bool }; public function Tracer(format_:TextFormat = null) { format = new TextFormat(); txt = new TextField(); //format var ref:* = (format_) ? format_ : {color:0x000000, size:12, font:'MS Gothic'}; PropertyScan( format, ref ); //prop var prop:Object = { x:0, y:0, autoSize:TextFieldAutoSize.LEFT }; PropertyScan( txt, prop ); //format done txt.defaultTextFormat = format; } // function has 4 params. implement dynamic param nomber. // x, y, width, height or Object/Array public function property(...args):void { const properties:Array = new Array('x','y','width','height'); var isArray:Boolean = (args[0] is Array) ? true : false; var params:* = isArray ? args[0] : args; var Q:uint = params.length; //Queue if (isArray || (Q<=4 && !(params is Object)) ) for (var i:uint=0; i<Q; i++) txt[properties[i]] = params[i]; else PropertyScan(txt, args[0]); } public function push(...args) :void { _log += Roller(args) + NEWLINE }; public function show() :void { txt.htmlText = _log }; public function dev(...args) :void { if (_isDev) _log += ("<b><font color='#ff0000'>" + Roller(args) + "</font></b>" + NEWLINE) ; } /* static functions, logic designed by madflash */ private static function Roller(...args) :String { var str:String = ""; if ( args.length <= 1 ) str += String(args); else for each(var e:Object in args){str += (String(e) + " ")}; return str; } private static function PropertyScan(target:*, ref:*) :void { if (target is Object && ref is Object) for(var key:String in ref) target[key] = ref[key]; } } Code Fullscreen Preview Fullscreen TextField trace target Object push TextFormat htmlText Boolean Math.log String TextField defaultTextFormat font TextFieldAutoSize.LEFT autoSize size trace color addChild length Array uint sort new page view favorite forked pv120 forked from: Tracer with textf.. madflash forked:0 favorite:0lines:68 (diff:11)