It doesn't work; it has bugs and doesn't make clean, deep copies.

----- Original Message ----- 
From: "Mark Walters" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <flashcoders@chattyfig.figleaf.com>
Sent: Monday, January 09, 2006 12:27 PM
Subject: Re: [Flashcoders] Duplicating an object without pointing to 
originalone


If you download the FlashRemoting source code, (
http://download.macromedia.com/pub/flashremoting/mx2004/components/actionscript_2.0/flashremoting_comp_sourcecode.zip
), you will have a new class mx.utils.ObjectCopy ... this will make a
new object, instead of a reference to the first.


On 1/9/06, JesterXL <[EMAIL PROTECTED]> wrote:
> For shallow copies, you can use a for in loop.
>
> var o:Object = {label: "test", data: 5};
> var copy:Object = {};
> for(var p in o)
> {
>     copy[p] = o[p];
> }
>
> However, if the o has properties that are objects, or arrays, you'll have
> problems because your copy will still contain references.  You need to
> utilize a recursive algorithm to continually dig down on the object.
> Recursion in Flash, however, is dangerous since you have a limit of 256, 
> and
> adjusting this in Flex only further increases the danger of locking up the
> comp.
>
> My suggestion is to provide a clone (or duplicate) method to those data
> objects you use to copy, and leave the implementation details to that 
> object
> rather than creating a catch-all method.
>
> Example:
>
> class MyObject
> {
>     public var label:String;
>     public var data:Number;
>
>     public function clone():MyObject
>     {
>         var o:MyObject = new MyObject();
>         o.label = label;
>         o.data = data;
>         return o;
>     }
> }
>
> ----- Original Message -----
> From: "Mendelsohn, Michael" <[EMAIL PROTECTED]>
> To: "Flashcoders mailing list" <flashcoders@chattyfig.figleaf.com>
> Sent: Monday, January 09, 2006 12:05 PM
> Subject: [Flashcoders] Duplicating an object without pointing to original
> one
>
>
> Hi list...
>
> 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.
>
> - MM
>
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders 

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

Reply via email to