How to copy an ArrayCollection by value

March 21st, 2008

I came across the requirement to copy an ArrayCollection by value instead of by reference. Here is the solutions I used:

1
2
3
4
5
private var myCollection:ArrayCollection = new ArrayCollection();
 
for (var k:Number = 0; k < myCurrentCollection.length; k++) {
	myCollection.addItem(mx.utils.ObjectUtil.copy(myCurrentCollection[k]));
}

Categories: Flex

Leave a comment

Comments Feed4 Comments

  1. Steven

    Just saw this, it works and is simpler.

    newAC = ObjectUtil.copy (oldAC) as ArrayCollection;

  2. Stephen

    Call to a possibly undefined method copy.

  3. Anton

    you have to import mx.utils.ObjectUtil

  4. Ravi

    Thanks a lott :)
    I got the solution after almost 5 hours.. but worth :)

Leave a comment

Feed

http://blog.jeffdouglas.com / How to copy an ArrayCollection by value

WordPress Appliance - Powered by TurnKey Linux