Francisc
Francisc

Reputation: 80415

Remove filtered out elements from ArrayCollection in ActionScript3

I have a big ArrayCollection variable. I want to filter it several times and each time assign the filtered result to a different ArrayCollection variable.

So if it has let's say people, fruits and cars. (for illustration purposes) I want to first filter it to only show people, assign the result to a people ArrayCollection, then filter it to show fruits and assign it to a fruits ArrayCollection and so on.

How can I do that? Not the filtering, but the assignment after filtering. Or is it faster to instead run a for-loop through the big ArrayCollection and just add each item into the corresponding smaller ArrayCollection?

Upvotes: 0

Views: 550

Answers (1)

Constantiner
Constantiner

Reputation: 14221

You can use mx.collections.ListCollectionView for that. Say you have the following original ArrayCollection:

var myCollection:ArrayCollection;

Now people:

var peopleList:ListCollectionView = new ListCollectionView(myCollection);
peopleList.filterFuntion = peopleFilterFuntion;
peopleList.refresh();

The same for fruits:

var fruitsList:ListCollectionView = new ListCollectionView(myCollection);
fruitsList.filterFuntion = fruitsFilterFuntion;
fruitsList.refresh();

And cars:

var carsList:ListCollectionView = new ListCollectionView(myCollection);
carsList.filterFuntion = carsFilterFuntion;
carsList.refresh();

Upvotes: 2

Related Questions