import com.oop.SelectionSystem; class com.oop.UIButton extends MovieClip { //-------------------------------------------------------------------------------------------- // Stores a reference to a SelectionSystem instance private var selectionSystem:Object; // Numeric id passed in by SelectionSystem when attached private var id:Number; // Keeps track of the selection status of this clip private var selected:Boolean; // Holds any custom visual information (such as title) private var itemData:Object; // stores the history of this item private var visited:Boolean; //-------------------------------------------------------------------------------------------- // constructor //-------------------------------------------------------------------------------------------- public function UIButton() { } //-------------------------------------------------------------------------------------------- /* Set up our reference, ID, and item data then take care of the clip's ui */ public function init(_selectionSystem:SelectionSystem, _id:Number, _itemData:Object ):Void { selectionSystem = _selectionSystem; itemData = _itemData; id = _id; _focusrect = false; initMouseEvents(); } //-------------------------------------------------------------------------------------------- /* Select this clip. It will stay visually selected because the mouse is rolled over it */ private function setSelected():Void { selected = visited = true; killMouseEvents(); } //-------------------------------------------------------------------------------------------- /* Unselect this clip */ private function setUnselected():Void { selected = false; initMouseEvents(); } //-------------------------------------------------------------------------------------------- private function setTitle(_val:Object):Void { // override } //-------------------------------------------------------------------------------------------- private function setPosition():Void { //override } //-------------------------------------------------------------------------------------------- /* Tell selectionSystem about the click and pass this clips ID with it */ private function handleRelease():Void { selectionSystem.setSelection(id); } //-------------------------------------------------------------------------------------------- private function handlePress():Void { //override } //-------------------------------------------------------------------------------------------- private function handleRollOver():Void { //override } //-------------------------------------------------------------------------------------------- private function handleRollOut():Void { //override } //-------------------------------------------------------------------------------------------- /* Capture all of our mouse events and pass them to the internal hander methods */ private function initMouseEvents() : Void { useHandCursor = false; onRollOver = handleRollOver; onRollOut = handleRollOut; onReleaseOutside = handleRollOut; onPress = handlePress; onRelease = handleRelease; } //-------------------------------------------------------------------------------------------- /* Remove all mouse events while the clip is selected */ private function killMouseEvents():Void { useHandCursor = false; delete onRollOver; delete onRollOut; delete onReleaseOutside; delete this.onPress; delete this.onRelease; } //-------------------------------------------------------------------------------------------- // Getter/Setters //-------------------------------------------------------------------------------------------- public function getId():Number { return id; } //-------------------------------------------------------------------------------------------- public function setId(_val:Number):Void { id = _val; } //-------------------------------------------------------------------------------------------- }