/src/com/cw/view/buttons/StopButton.as

https://bitbucket.org/404assassin/musicplayer
ActionScript | 133 lines | 79 code | 1 blank | 53 comment | 1 complexity | a8390c2814331899c62a7766e329e2ab MD5 | raw file
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // Christian Worley Development & Design
  3. // Copyright ${date} Christian Worley Development & Design
  4. // All Rights Reserved.
  5. ////////////////////////////////////////////////////////////////////////////////
  6. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  7. // Package Declaration
  8. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  9. package com.cw.view.buttons {
  10. /**
  11. * :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  12. * class description: StopButton
  13. * language version: ActionScript 3.0
  14. * player version: Flash 10.0
  15. * author: christian
  16. * created: Dec 26, 2011
  17. * TODO:
  18. * :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  19. */
  20. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  21. // Imports
  22. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  23. import com.cw.control.observer.IObserver;
  24. import com.cw.control.observer.ISubject;
  25. import com.cw.view.tweenStates.ButtonStates;
  26. import com.cw.view.tweenStates.ButtonOnOffStates;
  27. import flash.display.Sprite;
  28. import flash.events.Event;
  29. import flash.events.MouseEvent;
  30. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  31. // Class characteristics
  32. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  33. public class StopButton implements IButton, ISubject, IObserver {
  34. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  35. // Private Variables
  36. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  37. private var observer:ISubject;
  38. private var theButton:Sprite
  39. private var buttonStates:ButtonStates = new ButtonStates();
  40. private var buttonOnOffStates:ButtonOnOffStates = new ButtonOnOffStates();
  41. private var theStopButton:bttn_stop = new bttn_stop();
  42. private var theButtonState:String;
  43. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  44. // Constructor
  45. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  46. public function StopButton () {}
  47. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  48. // Public Interfaces
  49. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  50. public function setButton (theButtonState:String):void {
  51. this.theButtonState = theButtonState
  52. buttonBuild();
  53. }
  54. public function getButton ():Sprite {
  55. return theButton
  56. }
  57. /**
  58. * InvokedObserver interface, reference update, and subscription with
  59. * updated observer and adding subscription with addObserver(this).
  60. */
  61. public function addObserver (observer:ISubject):void {
  62. this.observer = observer;
  63. observer.addObserver(this);
  64. }
  65. /**
  66. * notify InvokedObservers
  67. */
  68. public function notifyObservers (infoObject:String):void {
  69. observer.notifyObservers(infoObject);
  70. }
  71. /**
  72. * remove an observer refrence from InvokedObserver
  73. */
  74. public function removeObserver (observer:ISubject):void {
  75. observer.removeObserver(this);
  76. }
  77. /**
  78. * receive notification from InvokedObserver
  79. */
  80. public function update (infoObject:String):void {
  81. if(hasOwnProperty(infoObject)) {
  82. this[infoObject]();
  83. }
  84. }
  85. /**
  86. * button on/off states via observer update
  87. * @param infoObject
  88. */
  89. public function theStopStateOn ():void {
  90. buttonOnOffStates.buttonStatesInterface(theStopButton.iconTop, 'OnState');
  91. }
  92. public function theStopStateOff ():void {
  93. buttonOnOffStates.buttonStatesInterface(theStopButton.iconTop, 'OffState');
  94. }
  95. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  96. // Private Methods
  97. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  98. private function buttonBuild ():void {
  99. theButton = new Sprite();
  100. theButton.addChild(theStopButton);
  101. addButtonEvents();
  102. theStopStateOff ();
  103. }
  104. private function addButtonEvents ():void {
  105. theStopButton.buttonMode = true;
  106. theStopButton.doubleClickEnabled = true;
  107. theStopButton.addEventListener(MouseEvent.CLICK, placementTargetUp);
  108. theStopButton.addEventListener(MouseEvent.MOUSE_DOWN, placementTargetDown);
  109. theStopButton.addEventListener(MouseEvent.MOUSE_OUT, placementTargetOut);
  110. theStopButton.addEventListener(MouseEvent.MOUSE_OVER, placementTargetOver);
  111. }
  112. private function placementTargetOver (overEvent:Event):void {
  113. buttonStates.buttonStatesInterface(theStopButton.background, 'OverState');
  114. buttonStates.buttonStatesInterface(theStopButton.iconBottom, 'OverState');
  115. }
  116. private function placementTargetOut (outEvent:Event):void {
  117. buttonStates.buttonStatesInterface(theStopButton.background, 'OutState');
  118. buttonStates.buttonStatesInterface(theStopButton.iconBottom, 'OutState');
  119. buttonOnOffStates.buttonStatesInterface(theStopButton.iconMiddle, 'OffState');
  120. }
  121. private function placementTargetDown (downEvent:Event):void {
  122. buttonStates.buttonStatesInterface(theStopButton.background, 'DownState');
  123. buttonStates.buttonStatesInterface(theStopButton.iconBottom, 'DownState');
  124. buttonOnOffStates.buttonStatesInterface(theStopButton.iconMiddle, 'OnState');
  125. }
  126. private function placementTargetUp (upEvent:Event):void {
  127. buttonStates.buttonStatesInterface(theStopButton.background, 'UpState');
  128. buttonOnOffStates.buttonStatesInterface(theStopButton.iconMiddle, 'OffState');
  129. notifyObservers(theButtonState);
  130. }
  131. }
  132. }