/** * * @author Michael M. R. Lueftenegger * @version 0.1 * @since 2004 */ class ast{ /******************************************************************************* * Autor : Michael M. R. Lueftenegger * Copyright : M.M.R. Lueftenegger, 2005 * Url : http://www.lueftenegger.at * email : office@lueftenegger.at ******************************************************************************* * ASToolBox is an Actionscript class which allows trace in all * player types and offers some other tools for debug purpose. * * Variables; * force_int_win 2005 v 0.1 * wnd_x 2005 v 0.1 * wnd_y 2005 v 0.1 * wnd_w 2005 v 0.1 * wnd_h 2005 v 0.1 * rep_line 2005 v 0.1 * rep_seperator 2005 v 0.1 * tab 2005 v 0.1 * avg_line 2006.01.30 v 0.2 * * funktionen: * * trace(String); 2005 v 0.1 * var_dump(object); 2005 v 0.1 * timer_start(); 2005 v 0.1 * timer_stop(); 2005 v 0.1 * timer_report(); 2005 v 0.1 * timer_clear(); 2006.01.30 v 0.2 * timer_avg(); 2006.01.30 v 0.2 *******************************************************************************/ public static var force_int_win:Boolean = true; // verwendet immer das eigene ausgabefenster static var wnd_x:Number = 10; // xposition des fensters static var wnd_y:Number = 10; // yposition des fensters static var wnd_w:Number = 500; // breite des fensters static var wnd_h:Number = 200; // höhe des fensters static var rep_line:String = "Messung %0 :\t %1 \tMillisekunden"; // Ausgabezeile für reportline static var avg_line:String = "Durchsch. :\t %0 \tMillisekunden"; // Ausgabezeile für timer_avg static var rep_seperator:String = "-------------------------------------------"; static var tab:String = " "; // Tabulatorstring für Analysestring private static var wnd_trace:MovieClip; // fasst das tracefenster; static var title:String = "ASToolBox - (C) 2005, M.M.R. Lueftenegger - http://www.lueftenegger.at"; static var times:Array = new Array(); // Fasst die Zeiten public /** * * @usage creates the qutput window if nessesary and traces l_text * @param l_text String * @return void */ static function trace(l_text){ if( force_int_win ){ if(!ast.wnd_trace ) wnd_trace = p_create_window(wnd_trace); wnd_trace.textfield.text += l_text+"\n"; }else{ switch (System.capabilities.playerType) { case "External": trace (l_text); break; case "StandAlone": case "ActiveX": case "PlugIn": default: if(!wnd_trace ) wnd_trace = p_create_window(wnd_trace); wnd_trace.textfield.text += l_text+"\n"; break; } } } /** * * @usage trace analysed, structured information of l_obj * @param l_obj Any Data * @return void */ static function var_dump(l_obj){ ast.trace( p_var_dump(l_obj) ); } /** * * @usage starts a measurement * @return Number - The ID of the measurement */ static function timer_start():Number{ return times.push( getTimer() )-1; } /** * * @usage stops a measurement * @param index ID of a running measurement. if index is not given, the last started measurement is stoped. * @return the duration of the stoped measurement */ static function timer_stop(index):Number{ (index == undefined)?index = times.length-1:null; times[index] = getTimer() - times[index]; return times[index]; } /** * * @usage traces a report of all done measurements * @return void */ static function timer_report(){ var i = -1; ast.trace(rep_seperator); while(i++ < times.length-1){ ast.trace( println(rep_line, [i+1,times[i]]) ); } ast.trace(rep_seperator); } /** * * @usage clears the timertable * @return void */ static function timer_clear(){ times = []; } /** * * @usage reports the average duration of a measurement based on all measurements in the timertable * @return void */ static function timer_avg(){ var i = -1; var sum = 0; while(i++ < times.length-1) sum += times[i]; ast.trace( println(avg_line, [sum/times.length]) ); } /** * * @usage replaces marks in line to entries in values * @param line String with marks for each value in values * @param values array with values wich replaces the marks in line * @return line with replaces marks * * println("%0 %1",["hello", "world!"]); * * returns "hello world!" */ static function println( line, values):String{ var i = -1; while(i++ < values.length-1){ line = line.split("%"+i).join( values[i] ); } return line; } /** * * @usage clears the textfield. * @return void */ static function clear(){ wnd_trace.textfield.text = ""; } private /** * * @usage draws a square in a given MC * @param x position x * @param y position y * @param w width * @param h height * @param mc MovieClip where the square is drawn in * @param l_color fillcolor * @return void */ static function p_draw_box(x,y,w,h,mc, l_color){ with(mc){ beginFill(l_color,100); lineStyle(0,0xeeeeee,100); moveTo(x,y+h); lineTo(x,y); lineTo(x+w,y); lineStyle(0,0x888888,100); lineTo(x+w,y+h); lineTo(x,y+h); endFill(); } } /** * * @usage draws a line in a given MC * @param x startpoint absolut x * @param y startpoint absolut y * @param w endpoint absolut x * @param h endpoint absolut y * @param mc * @param l_color * @return void */ static function p_draw_line(x,y,w,h,mc, l_color){ with(mc){ lineStyle(0,l_color,100); moveTo(x,y); lineTo(x+w,y+h); } } /** * * @usage creates the outputwindow * @param l_mc MovieClip where the window is created in * @return given MC (hm, what for? :-p) */ static function p_create_window(l_mc:MovieClip):MovieClip{ /* Zeichnet das Ausgabefenster * * @param l_mc Movieclip, in den geteichnet werden soll. * * return Movieclip, in den geteichnet wurde. */ // create window l_mc = _root.createEmptyMovieClip("wnd"+_root.getNextHighestDepth(),_root.getNextHighestDepth()); l_mc._x = wnd_x; l_mc._y = wnd_y; // create background var tmp = l_mc.createEmptyMovieClip("bg",0); p_draw_box(0,0,wnd_w,wnd_h,tmp,0xdddddd); // create titlebar var tmp = l_mc.createEmptyMovieClip("titlebar",1); p_draw_box(0,0,wnd_w,20,tmp,0xaaaaaa); tmp.createTextField ("textfield", 0, 2, 2, wnd_w-35, 18); tmp.textfield.html = true; tmp.textfield.htmlText = title; // eventhandler tmp.onPress = function(){ this._parent.startDrag(); } tmp.onRelease = function(){ this._parent.stopDrag(); } tmp.onReleaseOutside = tmp.onRelease; // closebutton var tmp = l_mc.createEmptyMovieClip("close",2); tmp._x = wnd_w-16; tmp._y = 6; p_draw_box(0,0,10,10,tmp,0xdddddd); p_draw_line(2,2,6,6,tmp,0x000000); p_draw_line(2,8,6,-6,tmp,0x000000); // eventhandler tmp.onRelease = function(){ this._parent.removeMovieClip(); delete ast.wnd_trace; } // minimizer var tmp = l_mc.createEmptyMovieClip("fade",3); tmp._x = wnd_w-30; tmp._y = 6; tmp.fade = false; tmp.myy = 0; p_draw_box(0,0,10,10,tmp,0xdddddd); p_draw_line(2,7,6,0,tmp,0x000000); // eventhandler tmp.onRelease = function(){ if( this.fade ){ this._parent.resizer._y = this.myy; this._parent.resizer._visible = true; }else{ this.myy = this._parent.resizer._y; this._parent.resizer._y = 50; this._parent.resizer._visible = false; } this._parent.resize(this._parent.resizer,true); this.fade = !this.fade; } // resizer var tmp = l_mc.createEmptyMovieClip("resizer",4); tmp._x = wnd_w; tmp._y = wnd_h; tmp.drag = false; p_draw_box(-10,-10,10,10,tmp,0x000000); // eventhandler tmp.onPress = function(){this.startDrag(false); this.drag = true;} tmp.onRelease = function(){ this.stopDrag(); this.drag = false; this._parent.resize(this)} tmp.onReleaseOutside = tmp.onRelease tmp.onMouseMove = function(){ if(this.drag)this._parent.resize(this);} // textfield l_mc.createTextField ("textfield", 5, 10, 30, wnd_w-20, wnd_h-50); l_mc.textfield.background =true; l_mc.textfield.backgroundColor = 0xffffff; l_mc.textfield.border = true; l_mc.textfield.wordWrap = true; l_mc.textfield.text = ""; l_mc.textfield.type = "input"; // resizefunction l_mc.resize = function(l_mc, l_discon){ if(!l_discon){ if(l_mc._x < 100)l_mc._x = 100; if(l_mc._y < 100)l_mc._y = 100; } this.bg._width = l_mc._x; this.bg._height = l_mc._y; this.titlebar._width = l_mc._x; this.close._x = l_mc._x-16; this.fade._x = l_mc._x-30; this.textfield._width = l_mc._x-30; this.textfield._height = l_mc._y-50; } return l_mc; } /** * * @usage creates teh analyzedata of an variable * @param l_arg used for rekurse call only * @param l_rek used for rekurse call only * @param l_name used for rekurse call only * @return String */ static function p_var_dump( l_arg , l_rek, l_name):String{ var output = ""; if(l_rek > 254) return "maximale Stufen erreicht.\n"; l_rek = (l_rek||0); for(var i = 0; i < l_rek; i++) output += ast.tab; if( l_name ){ output += l_name; var tmp = (30-output.length); for(var i = 0; i < tmp ;i++) output += "_"; } switch (typeof(l_arg)) { case "number": case "boolean": case "string": output += typeof(l_arg)+"['"+l_arg+"']\n"; break; case "object": case "movieclip": case "function": (l_arg instanceof Array)?output += "array\n":output += typeof(l_arg)+"\n"; for( i in l_arg) output += p_var_dump( l_arg[i], l_rek+1, i); break; default: output += typeof(l_arg)+"[]!nicht verarbeitet!\n"; } return output; } }