We had this question on the flexaussie mailing list a couple of days ago.
There is an example in the docs that works:

import mx.collections.ArrayCollection;
       import flash.utils.ByteArray;

       private function clone(source:Object):*
       {
           var myBA:ByteArray = new ByteArray();
           myBA.writeObject(source);
           myBA.position = 0;
           return(myBA.readObject());
       }


       private function init():void{
           var data:Array = [{name:"one",value:1},{name:"two",value:2}];
           var a:ArrayCollection = new ArrayCollection(data);

           var b:ArrayCollection = clone(a);

           b.getItemAt(0).value = "foo";
           trace(a.getItemAt (0).value);
           trace(b.getItemAt(0).value);
       }

Seems to work ok.

Hilary

--

On 4/20/07, Gordon Smith <[EMAIL PROTECTED]> wrote:

   I think that will give you two ArrayCollections which share the same
data items. For example, if you do

arrayCollection.setItemAt("foo", 0);
trace(arrayCollection2.getItemAt(0));

you'll probably get "foo".

- Gordon

 ------------------------------
*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Brian Holmes
*Sent:* Thursday, April 19, 2007 8:34 AM
*To:* [email protected]
*Subject:* RE: [flexcoders] Call by value instead of Call by reference
when copying ArrayCollection



 No loop required. Just create a new array collection with the source of
the old array collection.

arrayColletion2 = new ArrayCollection(arrayCollection1.source);

b..

 ------------------------------

*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of *manfred.maierhofer
*Sent:* Wednesday, April 18, 2007 11:30 AM
*To:* [email protected]
*Subject:* [flexcoders] Call by value instead of Call by reference when
copying ArrayCollection

  Hey guys,
is there a way to "copy" an ArrayCollection instead of referencing it
by ArrayCollection1 = ArrayCollection2;???

I can't believe that there is no way to do this, except cophying each
value in a loop.

Thanks,
Mane

 ------------------------------
***
The information in this e-mail is confidential and intended solely for the
individual or entity to whom it is addressed. If you have received this
e-mail in error please notify the sender by return e-mail delete this e-mail
and refrain from any disclosure or action based on the information.
***




--
Hilary

--

Reply via email to