Reputation: 1393
I want to iterate over an ArrayCollection in Flex while there can be items added and removed.
Since i didn't find a way to use a "classic" Iterator like in Java, which would do the job. I tried the Cursor. But it doesn't really work the way i want it to be ;) So how do I do it nicely ?
var cursor:IViewCursor = workingStack.createCursor();
while (!cursor.afterLast)
{
// Search
deepFirstSearchModified(cursor.current.node,nodeB,cursor.current.way);
// Delete Node
cursor.remove();
// Next Node
cursor.moveNext();
}
Upvotes: 3
Views: 11540
Reputation: 6411
In flex (or actionscript) any change that you do, is visible instantly. So you can do what you want in a for:
for (var i : Number = myArrayCollection.length; i > 0; i--) {
myArrayCollection.removeItemAt(i - 1);
}
I think that should work fine.
Upvotes: -1
Reputation: 14221
Try to use the following:
for (var i:int = myArrayCollection.length - 1; i >= 0; i--) {
myArrayCollection.removeItemAt(i);
}
Upvotes: 2
Reputation: 48127
Take a look at ActionLinq. It implements the .Net Linq2Objects pattern, including IEnumerable
. Of course, you need to be careful, because you are modifying the items you are iterating over...
var workingStack:ArrayCollection = getData();
var iterator:IEnumerable = Enumerable.from(workingStack);
for each(var item:String in iterator) {
doSomethingTo(workingStack);
}
Upvotes: 0
Reputation: 3024
I think better to use New Collection/Array for opertations as
private function parseSelectedItem(value:IListViewCollection):IListViewCollection{
var result:Array = new Array();
for each(var item:Object in value)
{
//result.push();
//result.pop();
}
return new ArrayCollection(result) ;
}
Hopes that helps
Upvotes: 3
Reputation: 3565
There is a solution for your problem:
http://www.ericfeminella.com/blog/actionscript-3-apis/
Have a look at the CollectionIterator class.
Cheers
Upvotes: 1