Copy ArrayCollection – not as a reference

By | 29 December, 2011

On my day job, i needed to copy an ArrayCollection to a different var so i could manipulate it without affecting the original. Went with this:

arraycollection2 = arraycollection1;

With this method, all i did to arraycollection2 was also happening to arraycollection1.

to copy arrayCollection1 to arrayCollection2 without making it a reference:

arrayCollection2 = ObjectUtil.copy(arrayCollection1) as ArrayCollection;

That’s that.

Oh, and make sure you import this:

import mx.utils.ObjectUtil;