views:

117

answers:

2

I have an ArrayCollection where I want to be able to bubble items up or down by one position. What is the best way to do this?

+2  A: 
var ac:ArrayCollection = new ArrayCollection(yourArraySource);
ac.removeItemAt(n); // where n > 0 and n < ac.length
ac.addItemAt( item, n-1); // where n>0 ... you should test for that

etc.

Robusto
+1  A: 

Combining Robusto's two function calls into a single line :)

ac.addItemAt(ac.removeItemAt(n), n-1);

The remove... functions on the ArrayList return the item being removed, so you can easily reposition it in the collection.

bedwyr