I have an ArrayCollection that is the dataProvider
for a spark.components.List, which has allowMultipleSelection="true"
. There is a "Remove Selected Items" button which initiates the removal of all the selected items from the ArrayCollection upon being clicked.
I currently use the following method:
myList.selectedIndices.sort(ascendingSort);
// remove items, counting backwards
for (var i:uint = myList.selectedIndices.length; i > 0; i--) {
myArrayCollection.removeItemAt(myList.selectedIndices[i-1]);
}
where ascendingSort
does what you expect ;). It works fine, and I know that it will always work.
However, I did take note that if I neglected the sort altogether, to my surprise the removal still worked. The reason for this turned out to be that, when the removeItemAt
is called, the selectedIndices
are correspondingly updated.
So my question is: Can one rely upon a removeItemAt
call updating the values in the selectedIndices
? or might that turn out to be different between runtimes and/or Flex SDK versions?
Obviously, if it is reliable then leaving out the sort would be a significant improvement.