Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterating over ArrayCollection while adding and removing items

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();

    }
like image 985
Dukeatcoding Avatar asked Jun 01 '26 12:06

Dukeatcoding


2 Answers

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

like image 53
Imran Avatar answered Jun 04 '26 13:06

Imran


Try to use the following:

for (var i:int = myArrayCollection.length - 1; i >= 0; i--) {
   myArrayCollection.removeItemAt(i);
}
like image 37
Constantiner Avatar answered Jun 04 '26 13:06

Constantiner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!