Created
July 24, 2008 15:57
-
-
Save jubishop/2194 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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