
Код:
class com.kidskilla.Debug{
private static var __oa:Array;
public function Debug(){
return;
}
public static function getWholeObj(obj):String{
if(typeof obj != "object") return obj.toString();
Debug.__oa = new Array();
Object.prototype._toString = function () {
if(typeof this == "function") return ""
Debug.__oa[Debug.__oa.length] = this;
var s = ""+typeof this+": {\n";
var ti = ""
for (var i in this) {
var c = (typeof this[i] == "object");
var type = c ? "" : " ("+typeof this[i]+")";
if(c){
var w
for(var j in Debug.__oa){
if(this[i] == Debug.__oa[j]){
w = true
ti = "(parent Object: "+j+" from top)"
};
}
if(!w) ti = this[i]._toString().split("\n").join("\n\t");
} else {
ti = this[i];
}
s += "\t["+i+"] = "+ti+type+" "+"\n";
}
s += "};";
return s;
}
Array.prototype._toString = Object.prototype._toString
_global.ASSetPropFlags(Array.prototype, "_toString", 1);
_global.ASSetPropFlags(Object.prototype, "_toString", 1);
var txt = obj._toString();
delete Array.prototype._toString;
delete Object.prototype._toString;
return txt;
}
public static function watch(obj:Object, prop:String, browser:Boolean):Void{
obj.watch(prop, function(prop, wuz, now, obj){
var func = browser ? Debug.browser : trace;
trace("\n"+prop+":\n\twas="+wuz+";\n\tnow="+now+";\n");
});
}
public static function trace(mess):Void{
trace(getWholeObj(mess))
}
public static function browser(mess):Void{
mess = Debug.getWholeObj(mess)
mess = mess.split("\n").join("\n<br>").split("\t").join("\t ").split(";[").join("<b>").split("] =").join("</b> =");;
var t = "javascript:w=window.open('', 'trace', 'Toolbar=0, Location=0, Directories=0, Status=0, Menubar=0, Scrollbar=0, Resizable=1, Copyhistory=0, Width=200, Height=200');";
t+="w.document.writeln(\"<html><head><title>Flash trace</title></head><body bgcolor='#FFFFFF' color='#000000'>"+mess+"<br></body></html>\");";
getURL(t);
}
public static function toString():String{
return "[Debug v1.0]";
}
}
@usage:
com.kidskilla.Debug.browser(my_obj);
com.kidskilla.Debug.browser(myValue)