Here is a start for you, from Dave Yang: http://quantumwave.com/flash/listObject.html. Somewhere he had a method to show arrays formatted in a way similar to what you show too, but I can't find that. This one works nicely though -- I tried a quickly modified version to see:

var o:Object = {
   x:5,
   a:['abc', 'def', 'ghi'],
   c:'a string',
d:{p1:17, p2:'something else', p3:{a:'here', b:'there'}, p4:[1, 2, 3, 4]}
};

function tabs() {
  var t = "";
  for (var i = 0; i<listObj.tabs; i++) {
     t += "\t";
  }
  return t;
}

function listObj(o) {
  listObj.tabs++;
  ASSetPropFlags(o, null, 6, true);
  var t = "";
  for (var p in o) {
      if (p != "__proto__") {
         var v = o[p];
         switch (typeof v) {
            case "function":
// if (_global[p] != null) t += (tabs()+p+"()"+"\n") + listObj(_global[p]);
   //            else t += (tabs()+p+"()"+"\n");
               break;
            case "object":
               t += (tabs()+p+"\n") + listObj(v);
               break;
            default:
               t += (tabs()+p+": "+v+"\n");
         }
         if (listObj.tabs < 1) t += "\n";
      }
  }
  t += "\n";
  listObj.tabs--;
  return t;
}

listObj.tabs = -1;

trace(listObj(o));

I'll look forward to your nice modified version :)

Helen

Andreas Weber wrote:

I'm quite sure that this must be around somewhere, but this time I didn't
have any luck searching the archives...

What I'm looking for is similar to a deep-copy/clone method (e.g.
Arul/Tatsuo
http://chattyfig.figleaf.com/mailman/htdig/flashcoders/2004-March/106149.htm
l) but instead of getting a clone of the object in return, I'd like to get a
String representation of the object.

Example of the desired functionality:

        o = {a:1, b:2, c:{c1:['a','b','c'], c2:true}};
        var s:String = universalToString(o);
        trace(s);

Output:   {a:1, b:2, c:{c1:['a','b','c'], c2:true}}

In my case the object will not contain any methods, just (deeply nested)
'vanilla' Objects, Arrays, Strings, Numbers and Booleans.

Thanks for any pointers!

--------------
Andreas Weber
motiondraw.com

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to