/src/com/cw/view/buttons/StopButton.as
ActionScript | 133 lines | 79 code | 1 blank | 53 comment | 1 complexity | a8390c2814331899c62a7766e329e2ab MD5 | raw file
- ////////////////////////////////////////////////////////////////////////////////
- // Christian Worley Development & Design
- // Copyright ${date} Christian Worley Development & Design
- // All Rights Reserved.
- ////////////////////////////////////////////////////////////////////////////////
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Package Declaration
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- package com.cw.view.buttons {
- /**
- * :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- * class description: StopButton
- * language version: ActionScript 3.0
- * player version: Flash 10.0
- * author: christian
- * created: Dec 26, 2011
- * TODO:
- * :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- */
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Imports
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- import com.cw.control.observer.IObserver;
- import com.cw.control.observer.ISubject;
- import com.cw.view.tweenStates.ButtonStates;
- import com.cw.view.tweenStates.ButtonOnOffStates;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.events.MouseEvent;
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Class characteristics
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- public class StopButton implements IButton, ISubject, IObserver {
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Private Variables
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- private var observer:ISubject;
- private var theButton:Sprite
- private var buttonStates:ButtonStates = new ButtonStates();
- private var buttonOnOffStates:ButtonOnOffStates = new ButtonOnOffStates();
- private var theStopButton:bttn_stop = new bttn_stop();
- private var theButtonState:String;
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Constructor
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- public function StopButton () {}
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Public Interfaces
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- public function setButton (theButtonState:String):void {
- this.theButtonState = theButtonState
- buttonBuild();
- }
- public function getButton ():Sprite {
- return theButton
- }
- /**
- * InvokedObserver interface, reference update, and subscription with
- * updated observer and adding subscription with addObserver(this).
- */
- public function addObserver (observer:ISubject):void {
- this.observer = observer;
- observer.addObserver(this);
- }
- /**
- * notify InvokedObservers
- */
- public function notifyObservers (infoObject:String):void {
- observer.notifyObservers(infoObject);
- }
- /**
- * remove an observer refrence from InvokedObserver
- */
- public function removeObserver (observer:ISubject):void {
- observer.removeObserver(this);
- }
- /**
- * receive notification from InvokedObserver
- */
- public function update (infoObject:String):void {
- if(hasOwnProperty(infoObject)) {
- this[infoObject]();
- }
- }
- /**
- * button on/off states via observer update
- * @param infoObject
- */
- public function theStopStateOn ():void {
- buttonOnOffStates.buttonStatesInterface(theStopButton.iconTop, 'OnState');
- }
- public function theStopStateOff ():void {
- buttonOnOffStates.buttonStatesInterface(theStopButton.iconTop, 'OffState');
- }
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- // Private Methods
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- private function buttonBuild ():void {
- theButton = new Sprite();
- theButton.addChild(theStopButton);
- addButtonEvents();
- theStopStateOff ();
- }
- private function addButtonEvents ():void {
- theStopButton.buttonMode = true;
- theStopButton.doubleClickEnabled = true;
- theStopButton.addEventListener(MouseEvent.CLICK, placementTargetUp);
- theStopButton.addEventListener(MouseEvent.MOUSE_DOWN, placementTargetDown);
- theStopButton.addEventListener(MouseEvent.MOUSE_OUT, placementTargetOut);
- theStopButton.addEventListener(MouseEvent.MOUSE_OVER, placementTargetOver);
- }
- private function placementTargetOver (overEvent:Event):void {
- buttonStates.buttonStatesInterface(theStopButton.background, 'OverState');
- buttonStates.buttonStatesInterface(theStopButton.iconBottom, 'OverState');
- }
- private function placementTargetOut (outEvent:Event):void {
- buttonStates.buttonStatesInterface(theStopButton.background, 'OutState');
- buttonStates.buttonStatesInterface(theStopButton.iconBottom, 'OutState');
- buttonOnOffStates.buttonStatesInterface(theStopButton.iconMiddle, 'OffState');
- }
- private function placementTargetDown (downEvent:Event):void {
- buttonStates.buttonStatesInterface(theStopButton.background, 'DownState');
- buttonStates.buttonStatesInterface(theStopButton.iconBottom, 'DownState');
- buttonOnOffStates.buttonStatesInterface(theStopButton.iconMiddle, 'OnState');
- }
- private function placementTargetUp (upEvent:Event):void {
- buttonStates.buttonStatesInterface(theStopButton.background, 'UpState');
- buttonOnOffStates.buttonStatesInterface(theStopButton.iconMiddle, 'OffState');
- notifyObservers(theButtonState);
- }
- }
- }