Browse Source

added flash.Lib.redirectTraces (fixed issue #1269)

Simon Krajewski 12 years ago
parent
commit
c24c51d8e2
1 changed files with 14 additions and 0 deletions
  1. 14 0
      std/flash/Lib.hx

+ 14 - 0
std/flash/Lib.hx

@@ -73,7 +73,21 @@ class Lib {
 	public inline static function as<T>( v : Dynamic, c : Class<T> ) : Null<T> {
 	public inline static function as<T>( v : Dynamic, c : Class<T> ) : Null<T> {
 		return untyped __as__(v,c);
 		return untyped __as__(v,c);
 	}
 	}
+	
+	public static function redirectTraces() {
+		if (flash.external.ExternalInterface.available)
+			haxe.Log.trace = traceToConsole;
+	}
 
 
+	static function traceToConsole(v : Dynamic, ?inf : haxe.PosInfos ) {
+		var type = if( inf != null && inf.customParams != null ) inf.customParams[0] else null;
+		if( type != "warn" && type != "info" && type != "debug" && type != "error" )
+			type = if( inf == null ) "error" else "log";
+		var str = if( inf == null ) "" else inf.fileName + ":" + inf.lineNumber + " : ";
+		try	str += Std.string(v) catch( e : Dynamic ) str += "????";
+		str = str.split("\\").join("\\\\");
+		flash.external.ExternalInterface.call("console."+type,str);
+	}
 }
 }