Schemaphic Systems Blog

Sharing experiences in Flash, Flex and AIR

Clone an ArrayCollection

with 4 comments

Easy way to clone an ArrayCollection without interfering the current collection.

/*
@usage:
var myCollection:ArrayCollection = new ArrayCollection( [1, 2, 3, 4] );
var clonedCollection:ArrayCollection = clone( myCollection );

trace( myCollection.toString() ); // 1,2,3,4
trace( clonedCollection.toString() ); // 1,2,3,4

clonedCollection.removeItemAt(0);

trace( myCollection.toString() ); // 1,2,3,4
trace( clonedCollection.toString() ); // 2,3,4
*/

public function clone( value:ArrayCollection ) : ArrayCollection
{
    var newCollection:ArrayCollection = new ArrayCollection( value.toArray() );
    return newCollection;
}
Advertisements

Written by Deepanjan Das

September 16, 2010 at 8:24 AM

4 Responses

Subscribe to comments with RSS.

  1. I simply want to tell you that I am just new to blogging and actually enjoyed your website. Likely I’m planning to bookmark your site . You really have beneficial articles. Cheers for sharing your webpage.

    Berry Speagle

    February 10, 2011 at 7:02 PM

  2. Mind-blowing article bro. This kind of is just a enormously nicely structured piece of writing, just the awesome info I was looking regarding. I praise you

    ptz camera review

    February 13, 2011 at 1:01 PM

  3. Does work. Causes my application to stall… which is the same effect I get when i do this:

    cloneAC = originalAC;

    brds

    July 22, 2011 at 8:14 PM

  4. Hi…..
    I have used your method to make copy of one array collection into another array collection, this works fine but when I change the value of one item into array collection then this change also reflect in another array collection which is I don’t want.

    Kindly please tell me why this happening and how to resolve this.

    Dhirender

    June 29, 2013 at 11:11 AM


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: