Arrays and Functions can have other properties attached to it. But my .toString() method and ActionScript() function does not account for it. Now I’ve rewritten the code to include those other properties as well. Also now it takes care of the properties with undefined values. Take a look at the new ActionScript() function here.

[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....
*/

*/[/pre]


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

/*
************************************************************
Developed by R.Arul Kumaran [[email protected]] *
for more code keep visiting [www.shockwave-india.com/blog] *
************************************************************
version 3.7 Last updated on 1 Feb, 2006
Thanks to Ampre[[email protected]] for the initial improvements to my Object.toAS() code
*/
/*
| Object.toString() - Create a actionscript string for the given object with out circular references
| Useful for tracing objects for local and remote debugging
|
| ActionScript(Object, 'name_of_the_variable') - gets complete reusable actionscript of the Object including circular reference
*/
_global.ActionScript = function(obj, name) {
ActionScript._Dump = [];
var str = name+' = '+obj.toString(name)+ActionScript.lineBrake+ActionScript._Dump.join(ActionScript.lineBrake);
delete ActionScript._Dump;
return str;
};
ActionScript.lineBrake = "n";
ActionScript.spacer = "t";
ActionScript.makeString = function(t, name, spacer) {
var y = typeof (t);
switch (y) {
case "object" :
return (ActionScript.getString(t, name, spacer, t instanceof Array ? 1 : 0));
case "function" :
return (ActionScript.getString(t, name, spacer, 2));
case "boolean" :
case "number" :
return (t);
case "string" :
return (t.toString());
case "movieclip" :
var m = t._target.split('/').join('.');
return (m.length>1 ? '_root'+m : '_root');
default :
return (y == '' ? t : y);
}
};
ActionScript.getString = function(t, name, spacer, mode) {
var s = new String();
if (spacer == undefined) {
spacer = '';
}
t.__name__ = name;
t.IsCircularReference = true;
ASSetPropFlags(t, "IsCircularReference,__name__", 1);
for (var i in t) {
var special = false;
var l = i.length;
while (l--) {
var c = i.charAt(l);
if ("abcdefghijklmnopqrstuvwxyz0123456789_".indexOf(c.toLowerCase())<0) { special = true; break; } } if (!t[i].IsCircularReference) { if (special) { ActionScript._Dump.push(t.__name__+'["'+i+'"] = '+ActionScript.makeString(t[i], name+'.'+i, spacer+ActionScript.spacer)+';'); } else { switch (mode) { case 0 : //Objects var rS = ActionScript.makeString(t[i], name+'.'+i, spacer+ActionScript.spacer); if (rS != '' && rS != undefined) { s += ActionScript.lineBrake+spacer+ActionScript.spacer+i+':'+rS+", "; } break; default : //Object definition if (isNaN(i)) { var rS = ActionScript.makeString(t[i], name+'.'+i, ''); if (rS != '' && rS != undefined) { ActionScript._Dump.push(t.__name__+'.'+i+' = '+rS+';'); } } } } } else { if (isNaN(i)) { ActionScript._Dump.push(special ? t.__name__+'["'+i+'"] = '+t[i].__name__ : t.__name__+'.'+i+' = '+t[i].__name__+';'); } } } switch (mode) { case 1 : //Array for (var i = 0; i