User Guide
Collection interface (Flash Professional only) 175
Description
Method; removes the specified item from the collection. Because Collection.removeItem()
dynamically reduces the size of the collection, do not call this method while looping through an
iterator.
Example
The following example calls removeItem():
var myColl:mx.utils.Collection;
myColl = _parent.thisShelf.MyCompactDiscs;
// get this from a text input box
var removeArtist:String = _parent.tArtistToRemove.text;
var removeSize:Number = 0;
if (myColl.isEmpty()) {
trace("No CDs in the collection");
}
else {
var toRemove:Array = new Array();
var itr:mx.utils.Iterator = myColl.getIterator();
var cd:CompactDisc = new CompactDisc();
var title:String = "";
var artist:String = "";
while (itr.hasNext()) {
cd = CompactDisc(itr.next());
title = cd.Title;
artist = cd.Artist;
if(artist == removeArtist) {
// mark this artist for deletion
removeSize = toRemove.push(cd);
trace("*** Marked for deletion: " + artist + "|" + title);
}
}
// after while loop, remove the bad ones
var removeCD:CompactDisc = new CompactDisc();
for(i = 0; i < removeSize; i++) {
removeCD = toRemove[i];
trace("Removing: " + removeCD.Artist + "|" + removeCD.Title);
myColl.removeItem(removeCD);
}
}