As you all already know my Object.toAS() code does fail with circular references. Ampre has replied with the following code in prototype, which is sleeker and also can addresses the circular reference issue to some extent.

Here is that code

[UPDATE] included the ActionScript 3 version as well 🙂 It became lot more simpler with the regular expressions

/*
 ************************************************************
   Developed by R.Arul Kumaran [[email protected]]
   for more code keep visiting [www.luracast.com/all/blog]
 ************************************************************
 */
 /*
Coming Soon....
*/


 */
/*
/*
 ************************************************************
   Developed by R.Arul Kumaran [[email protected]]
   for more code keep visiting [www.luracast.com/all/blog]
 ************************************************************
 */
Object.prototype.toString = function() {
        var s;
        if (this.$tmpsvar) {
                return "this";
        }
        this.$tmpsvar = true;
        ASSetPropFlags(this, "$tmpsvar", 1);
        for (var i in this) {
                s += i+":"+((typeof (this[i]) == 'string') ? "'"+this[i]+"'" : this[i])+",";
        }
        if (s.length) {
                s = substring(s, 1, s.length-1);
        }
        delete this.$tmpsvar;
        return "{"+s+"}";
};
Array.prototype.$toString = Array.prototype.toString;
Array.prototype.toString = function() {
        return "["+this.$toString()+"]";
};
ASSetPropFlags(Array.prototype, ["$toString"], 1);

Usage Example

qz = {abcd:20, ddsasd:88, phft:"cat", dd:{aaa:33, no:false, yes:true}};
qz.qzzz = qz;
trace(qz);
//traces '{qzzz:this,abcd:20,ddsasd:88,phft:'cat',dd:{aaa:33,no:false,yes:true}}'