I use this function (think I got it from Darron Schall's blog) to do a deep copy. I had the same experience as Jesse with mx.utils.ObjectCopy not working correctly...
// ---------------------------------------------- // copy an object function copyObject(obj) { // create a "new" object or array depending on the type of obj var copy = (obj instanceof Array) ? [] : {}; // loop over all of the value in the object or the array to copy them for(var i in obj) { // assign a temporarity value for the data inside the object var item = obj[i]; // check to see if the data is complex or primitive switch(item instanceof Array || item instanceof Object) { case true: // if the data inside of the complex type is still complex, we need to // break that down further, so call copyObject again on that complex // item copy[i] = copyObject(item); break; default: // the data inside is primitive, so just copy it (this is a value copy) copy[i] = item; } } return copy; } best, - rajat On 1/10/06, zwetan <[EMAIL PROTECTED]> wrote: > > > Hi, > > > > > How do you duplicate an object {bool:true, val:5} in another variable > > without pointing to the original one, and without having to create a > > constructor. In Director, there's a duplicate() method in Lingo. Is > > there an equivalent way to do this in Flash? > > > > Something like this, but which would actually work: > > > > var h = {a:true}; > > var g = h; > > trace(h.a); // true > > g.a = false; > > trace(h.a); // false, but want to be true, so it's separate from g > > object. > > > > I recently released a library which add this functionality > of deep copy to all core objects > > You can download it here > http://www.burrrn.com/projects/core2.html > > > your small exemple will turn like that: > > var h = { a:true }; > var g = h.copy(); > trace( h.a ); //true > g.a = false; > trace( h.a ); //true > > > > zwetan > > > > > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > -- Rajat Paharia [EMAIL PROTECTED] http://www.bunchball.com http://www.rootburn.com _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders