There are many ways to copy an arrayCOllection to another one.Here is a couple of them
Initialize the new array with the older arrayCollection's source.
Example :var a : ArrayCollection = new ArrayCollection(array);
Use mx.utls.ObjectUtil.Copy
Example :var arrayCollection1 : ArrayCollection = ObjectUtil.copy(arrayCollection2)
Hope it helps!
10 comments:
yes it doses help. thx a lot
In the instance when you have to build your own ArrayCollection from multiple data sources the following shortened code (I use a loop to create the parent and an inside loop to create the child) to add the child to the parent. To copy one ArrayCollection into another, try this:
var childArray:ArrayCollection([{label:"ALL",data:null},
{label:"OTHER",data:"OTHER"},
{label:"SOME",data:"PARTIAL"}]);
var parentArray:ArrayCollection
([{label:"ALL",data:null,, children:new ArrayCollection(_ChildAC.toArray())}}]);
Using the toArray clones the array instead of creating a reference to it. This allows you to reuse the variable inside the loop instead of trying to create multiple new arrays.
Thank you. This is very helpful
You have shown one of the best way to take a copying of an arraycollection :)
Thanks men.
mx.utls.ObjectUtil.Copy didn't work for me, don't know why, but the first one works very well.
It was very helpful.
Another way to copy one object "a" to a "b":
for each (var item:Object in a){
b.addItem(item)
}
Thanxs .. Kip Sharing ..!!
Hi machi,
Thanks It really works :) Good to see your blog too.
Many Thanks! for cool trips
It's very Helpful.. Before this, i tried:
var arr1: ArrayCollection = new ArrayCollection();
var arr2:ArrayCollection = new ArrayCollection();
then i add some objects in arr1 as arr1.addItem(obj); and its a dynamic list.. Its varies user type a charcter..
And arr2 have server original array collection. At some particular point, i need original array in datagrid..
So i moved arr2 to arr1 as
arr2 = arr1;
But i get only arr1 objects not original objects..
Pls tell the diff b/w arr1.source = arr2.souce and arr1 = arr2
This doesn't actually copy the ArrayCollection, only the objects. ArrayCollections have filter/sorting backing, which, if using either one of these methods, is not provided.
Post a Comment