Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created July 24, 2008 15:57
Show Gist options
  • Save jubishop/2194 to your computer and use it in GitHub Desktop.
Save jubishop/2194 to your computer and use it in GitHub Desktop.
package jubishop {
import mx.collections.ArrayCollection;
public class Set extends ArrayCollection {
public function removeItem(item:Object):int {
var itemIndex:int = getItemIndex(item);
if (itemIndex == -1) return -1;
removeItemAt(itemIndex);
return itemIndex;
}
public override function addItem(item:Object):void {
removeItem(item);
super.addItem(item);
}
public override function addItemAt(item:Object, index:int):void {
if (getItemIndex(item) == index) return;
var removedIndex:int = removeItem(item);
if (removedIndex != -1 && removedIndex < index) index--;
super.addItemAt(item, index);
}
public override function setItemAt(item:Object, index:int):Object {
if (getItemIndex(item) == index) return item;
var removedIndex:int = removeItem(item);
if (removedIndex != -1 && removedIndex < index) index--;
return super.setItemAt(item, index);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment