Posted on Friday 30 December 2005
Ah!, the simple joy of prototype hacking. I needed to have a recursive trace in FlashCom to look into recordsets I'm retrieving from amfphp. Picked this up from proto (submitted by user kk) and changed a couple of lines to get it working in FlashCom:
var oa;
Object.prototype.toString = function () {
if(typeof this == "function") return "";
try{
var something = oa.length;
}
catch(e)
{
oa = new Array();
}
oa.push(this);
var s = "{\n";
var ti = ""
for (var i in this) {
if(i == 'constructor' || typeof(this[i]) == "function")
{
continue;
}
var c = (typeof this[i] == "object");
var type = c ? "" : " ("+typeof this[i]+")";
if(c){
var w;
for(var j in oa){
if(this[i] == oa[j]){
w = true
ti = "";
};
}
if(!w)
{
try
{
ti = this[i].toString().split("\n").join("\n ");
}
catch(e)
{
ti = this[i];
}
}
} else {
ti = this[i];
}
s += " "+i+" : "+ti+" "+"\n";
}
s += "}";
oa = null;
return s;
}
Array.prototype.toString = Object.prototype.toString;
Save as tracehack.asc in the scriptlib folder, and use load("tracehack.asc") whenever you feel like debugging. Now every time you trace an object instead of seeing [Object object] in the app inspector you'll see a deep trace of the object with properties and whatnot. There seems to be an issue with large traces though... You might want to call substr(0, 1023) before tracing if you get "string too long" errors.


