This code snippet helps to get the real insight of an object instead of returning ‘[object object]’ while tracing. Now I’ve completely rewritten it to take care of circular references, escaping quotes in Strings, and function references. Also I’ve created a “ActionScript” function to get the complete picture of the object. We can use the produced actionscript to rebuild the objects.

[cc lang=”actionscript3″]

Object.toString() - Create a actionscript string for the given object with out showing circular references.

ActionScript(Object, 'name_of_the_variable') - gets complete reusable actionscript of the Object including circular reference.

[/cc]


Take a look at the the following usage example
[cc lang=”actionscript3″]

#include "toString.as"
var mVar = {num:20, str:"Escaped "Double Quotes"", str2:"Escaped 'Single Quotes'", arr:['str', 30], obj:{aa:33, bol:true}};
mVar.self = mVar;
mVar.func = function() {
        trace("me");
};
mVar.obj.parent = mVar.obj;
mVar.obj.parents = mVar;
mVar.arr.push(mVar);
mVar.arr.push(mVar.arr);
trace(mVar);
//traces '{func:function(){}, num:20, str:"Escaped "Double Quotes"", str2:"Escaped 'Single Quotes'", arr:["str",30], obj:{aa:33, bol:true}}'
trace(ActionScript(mVar, 'MyVAR'));
//traces the following
MyVAR = {func:function(){}, num:20, str:"Escaped "Double Quotes"", str2:"Escaped 'Single Quotes'", arr:["str",30], obj:{aa:33, bol:true}}
MyVAR.self = MyVAR
MyVAR.arr[2] = MyVAR
MyVAR.arr[3] = MyVAR.arr
MyVAR.obj.parents = MyVAR
MyVAR.obj.parent = MyVAR.obj

[/cc]


It can be downloaded from here.