Browse Source

added setColor.

Nicolas Cannasse 19 years ago
parent
commit
be4d0c7847
3 changed files with 37 additions and 11 deletions
  1. 17 7
      std/flash/Boot.hx
  2. 14 4
      std/flash9/Boot.hx
  3. 6 0
      std/haxe/Log.hx

+ 17 - 7
std/flash/Boot.hx

@@ -151,17 +151,27 @@ class Boot {
 			}
 			}
 		}
 		}
 	}
 	}
+	
+	private static function getTrace() : flash.TextField {
+		var root = flash.Lib.current;
+		var tf : flash.TextField = root.__trace_txt;
+		if( tf == null ) {
+			root.createTextField("__trace_txt",1048500,0,0,Stage.width,Stage.height+30);
+			tf = root.__trace_txt;
+			tf.selectable = false;
+			root.__trace_lines = new Array<String>();
+		}
+		return tf;
+	}
 
 
+	private static function __set_trace_color( rgb : Int ) {
+		getTrace().textColor = rgb;
+	}
+	
 	private static function __trace(v,inf : haxe.PosInfos) {
 	private static function __trace(v,inf : haxe.PosInfos) {
 		untyped {
 		untyped {
 			var root = flash.Lib.current;
 			var root = flash.Lib.current;
-			var tf : flash.TextField = root.__trace_txt;
-			if( tf == null ) {
-				root.createTextField("__trace_txt",1048500,0,0,Stage.width,Stage.height+30);
-				tf = root.__trace_txt;
-				tf.selectable = false;
-				root.__trace_lines = new Array<String>();
-			}
+			var tf = getTrace();
 			var s = inf.fileName+(if( inf.lineNumber == null ) "" else ":"+inf.lineNumber)+": "+__string_rec(v,"");
 			var s = inf.fileName+(if( inf.lineNumber == null ) "" else ":"+inf.lineNumber)+": "+__string_rec(v,"");
 			var lines : Array<String> = root.__trace_lines["concat"](s.split("\n"));
 			var lines : Array<String> = root.__trace_lines["concat"](s.split("\n"));
 			tf.text = lines.join("\n");
 			tf.text = lines.join("\n");

+ 14 - 4
std/flash9/Boot.hx

@@ -72,8 +72,12 @@ class Boot extends flash.display.MovieClip {
 		tf = null;
 		tf = null;
 		lines = new Array();
 		lines = new Array();
 	}
 	}
-
-	static function __trace( v : Dynamic, pos : haxe.PosInfos ) {
+	
+	static function __set_trace_color(rgb) {
+		getTrace().textColor = rgb;
+	}
+	
+	static function getTrace() {
 		var mc = flash.Lib.current;
 		var mc = flash.Lib.current;
 		if( tf == null ) {
 		if( tf == null ) {
 			tf = new flash.text.TextField();
 			tf = new flash.text.TextField();
@@ -82,10 +86,16 @@ class Boot extends flash.display.MovieClip {
 			tf.autoSize = flash.text.TextFieldAutoSize.LEFT;
 			tf.autoSize = flash.text.TextFieldAutoSize.LEFT;
 		}
 		}
 		mc.addChild(tf); // on top
 		mc.addChild(tf); // on top
+		return tf;
+	}
+
+	static function __trace( v : Dynamic, pos : haxe.PosInfos ) {
+		var tf = getTrace();
 		var pstr = if( pos == null ) "(null)" else pos.fileName+":"+pos.lineNumber;
 		var pstr = if( pos == null ) "(null)" else pos.fileName+":"+pos.lineNumber;
 		lines = lines.concat((pstr +": "+__string_rec(v,"")).split("\n"));
 		lines = lines.concat((pstr +": "+__string_rec(v,"")).split("\n"));
 		tf.text = lines.join("\n");
 		tf.text = lines.join("\n");
-		while( tf.height > mc.stage.stageHeight ) {
+		var stage = flash.Lib.current.stage;
+		while( tf.height > stage.stageHeight ) {
 			lines.shift();
 			lines.shift();
 			tf.text = lines.join("\n");
 			tf.text = lines.join("\n");
 		}
 		}
@@ -130,4 +140,4 @@ class Boot extends flash.display.MovieClip {
 		return new String(v);
 		return new String(v);
 	}
 	}
 
 
-}
+}

+ 6 - 0
std/haxe/Log.hx

@@ -47,5 +47,11 @@ class Log {
 		#else error
 		#else error
 		#end
 		#end
 	}
 	}
+	
+	#if flash
+	public static f9dynamic function setColor( rgb : Int ) {
+		untyped flash.Boot.__set_trace_color(rgb);
+	}
+	#end
 
 
 }
 }