missEmm

Panel Class

Apr 24th, 2011
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package code {
  2.    
  3.     import flash.display.MovieClip;
  4.     import flash.events.Event;
  5.     import flash.events.MouseEvent;
  6.     import flash.geom.Point;
  7.    
  8.    
  9.     public class Panel extends MovieClip {
  10.         public var distanceX:Number = 0;
  11.         public var button:MainMenuButton;
  12.         public var buttons:Array = new Array();
  13.         public var myDoc:Document;
  14.         private var selectedButton:MainMenuButton;
  15.         public var buttonNames:Array = new Array();
  16.         public var currentName:String = new String();
  17.         public var currentButton:MainMenuButton;
  18.         public var previousSubMenu:SubMenu;
  19.         public var currentSubMenu:SubMenu;
  20.  
  21.        
  22.         public function Panel(aDoc:Document) {
  23.             // constructor code
  24.             buttonNames.push("ScoreCard","Point Shop","Search","Playbook","Testing","Account");
  25.  
  26.             myDoc = aDoc;
  27.            
  28.             x= -200;
  29.            
  30.             for(var i:int=0; i<6; i++)
  31.             {
  32.                 button = new MainMenuButton();
  33.                 addChild(button);
  34.                 button.x=(buttons.length)*85+175;
  35.                 buttons.push(button);
  36.                 button.btnName.text = buttonNames[i];
  37.                 button.name= buttonNames[i];
  38.  
  39.             }
  40.            
  41.            
  42.             addEventListener(MouseEvent.MOUSE_DOWN, onMD);
  43.             addEventListener(MouseEvent.MOUSE_UP, onMU);
  44.         }
  45.        
  46.         private function onMU(e:MouseEvent):void
  47.         {
  48.             trace("Mouse Up tehehehahahaha");
  49.            
  50.             removeEventListener(Event.ENTER_FRAME, onDrag);
  51.             //var myPointer:Number;
  52.             //myPointer = myDoc.pointer.x;
  53.             var globalPointerPos:Point = myDoc.pointer.parent.localToGlobal(new Point(myDoc.pointer.x, myDoc.pointer.y));
  54.            
  55.             for (var i:Number = 0; i < buttons.length; i++ ) {
  56.                 var globalButtonPos:Point = this.localToGlobal(new Point(buttons[i].x, buttons[i].y));
  57.                 if (globalButtonPos.x > globalPointerPos.x)
  58.                 {
  59.  
  60.                     break;
  61.                 }
  62.             }
  63.            
  64.             i = i - 1;
  65.             if (i < 0)
  66.             {
  67.                 i = 0;
  68.             }
  69.            
  70.             var tempButton:MainMenuButton = buttons[i];
  71.             trace(tempButton.name);
  72.             var globalTempButtonPos:Point = this.localToGlobal(new Point(tempButton.x, tempButton.y));
  73.             var tempButtonCenterX:Number = globalTempButtonPos.x + tempButton.width/2;
  74.             this.x = this.x + (globalPointerPos.x - tempButtonCenterX);
  75.             if (selectedButton != null)
  76.             {
  77.                 selectedButton.highlight_mc.visible=false;
  78.                 selectedButton.highlight_mc.y=-1;
  79.  
  80.             }
  81.             selectedButton = tempButton;
  82.             selectedButton.highlight_mc.visible=true;              
  83.             selectedButton.highlight_mc.y=-1;
  84.            
  85.             currentButton = selectedButton;
  86.             //subMenuSelection()
  87.            
  88.         }
  89.        
  90.         //public function subMenuSelection():void
  91. //      {
  92. //          var ScoreCardSubMenu:SubMenu = new SubMenu();
  93. //          currentSubMenu = ScoreCardSubMenu;
  94. //
  95. //         
  96. //          if(currentButton.name == "ScoreCard"){
  97. //             
  98. //              //currentButton.onSearchBtn();
  99. //              currentSubMenu = previousSubMenu;
  100. //                  removeChild(previousSubMenu);
  101. //                  trace("removed");
  102. //             
  103. //              trace("Search button selection");
  104. //              //var ScoreCardSubMenu:SubMenu = new SubMenu();
  105. //              addChild(ScoreCardSubMenu);
  106. //              ScoreCardSubMenu.x=-150;
  107. //              ScoreCardSubMenu.y=60;
  108. //              if(currentSubMenu != null)
  109. //              /*{
  110. //                  currentSubMenu = previousSubMenu;
  111. //                  removeChild(previousSubMenu);
  112. //                  trace("removed");
  113. //
  114. //              }*/
  115. //              currentSubMenu=SearchSubMenu;
  116. //             
  117. //          }
  118. //          else if(currentButton.name == "Point Shop")
  119. //          {
  120. //              //currentButton.onPointShopBtn();
  121. //              trace("Pointshop button selection");
  122. //              currentSubMenu = previousSubMenu;
  123. //                  removeChild(previousSubMenu);
  124. //                  trace("removed");
  125. //             
  126. //              var PointShopSubMenu:SubMenu = new SubMenu;
  127. //              addChild(PointShopSubMenu);
  128. //              PointShopSubMenu.x=-150;
  129. //              PointShopSubMenu.y=60;
  130. //              /*if(currentSubMenu != null)
  131. //              {
  132. //                  currentSubMenu = previousSubMenu;
  133. //                  removeChild(previousSubMenu);  
  134. //                  trace("removed");
  135. //
  136. //              }*/
  137. //              currentSubMenu=PointShopSubMenu;
  138. //
  139. //
  140. //             
  141. //          }
  142. //          else if(currentButton.name == "Search")
  143. //          {
  144. //              //currentButton.onScorecardBtn();
  145. //              currentSubMenu = previousSubMenu;
  146. //                  removeChild(previousSubMenu);
  147. //                  trace("removed");
  148. //              trace("ScoreCard button selection");
  149. //              var SearchSubMenu:SubMenu = new SubMenu;
  150. //              addChild(SearchSubMenu);
  151. //              SearchSubMenu.x=-150;
  152. //              SearchSubMenu.y=60;
  153. //              /*if(currentSubMenu != null)
  154. //              {
  155. //                  currentSubMenu = previousSubMenu;
  156. //                  removeChild(previousSubMenu);
  157. //                  trace("removed");
  158. //
  159. //              }*/
  160. //             
  161. //              currentSubMenu = SearchSubMenu;
  162. //
  163. //          }
  164. //          else if(currentButton.name == "Testing")
  165. //          {
  166. //              //currentButton.onTestingBtn();
  167. //              currentSubMenu = previousSubMenu;
  168. //                  removeChild(previousSubMenu);
  169. //                  trace("removed");
  170. //              trace("Playbook button selection");
  171. //              var TestingSubMenu:SubMenu = new SubMenu;
  172. //              addChild(TestingSubMenu);
  173. //              TestingSubMenu.x=-150;
  174. //              TestingSubMenu.y=60;
  175. //              /*if(currentSubMenu != null)
  176. //              {
  177. //                  currentSubMenu = previousSubMenu;
  178. //                  removeChild(previousSubMenu);
  179. //                  trace("removed");
  180. //
  181. //              }*/
  182. //              currentSubMenu = TestingSubMenu;
  183. //             
  184. //          }
  185. //          else if(currentButton.name == "Playbook")
  186. //          {
  187. //              //currentButton.onPlaybookBtn();
  188. //              currentSubMenu = previousSubMenu;
  189. //                  removeChild(previousSubMenu);
  190. //                  trace("removed");
  191. //              trace("Playbook button selection");
  192. //              var PlaybookSubMenu:SubMenu = new SubMenu;
  193. //              addChild(PlaybookSubMenu);
  194. //              PlaybookSubMenu.x=-150;
  195. //              PlaybookSubMenu.y=60;
  196. //              /*if(currentSubMenu != null)
  197. //              {
  198. //                  currentSubMenu = previousSubMenu;
  199. //                  removeChild(previousSubMenu);
  200. //                  trace("removed");
  201. //                 
  202. //              }*/
  203. //              currentSubMenu = PlaybookSubMenu;
  204. //
  205. //          }
  206. //         
  207. //          else
  208. //          {
  209. //              //currentButton.onAccountBtn();
  210. //              currentSubMenu = previousSubMenu;
  211. //                  removeChild(previousSubMenu);
  212. //                  trace("removed");
  213. //              trace("account button selection");
  214. //              var AccountSubMenu:SubMenu = new SubMenu;
  215. //              addChild(AccountSubMenu);
  216. //              AccountSubMenu.x=-150;
  217. //              AccountSubMenu.y=60;   
  218. //              /*if(currentSubMenu != null)
  219. //              {
  220. //                  currentSubMenu = previousSubMenu;
  221. //                  removeChild(previousSubMenu);
  222. //                  trace("removed");
  223. //              }*/
  224. //              currentSubMenu = AccountSubMenu;
  225. //
  226. //          }
  227. //         
  228. //      }
  229.        
  230.         private function onMD(e:MouseEvent):void
  231.         {          
  232.            
  233.             //trace(currentButton);
  234.             if(currentButton != null)
  235.             {
  236.                 currentButton.highlight_mc.visible=false;
  237.             }
  238.             trace("MOUSE DOWN WHOAHAHAHAHH");
  239.             //i'm subtracting panel's coordinate from the mouse coordinate to save it's number as the distanceX
  240.             //this will create a drag because if the distance isn't the same, the object wont drag with the mouse
  241.             distanceX = parent.mouseX - this.x;
  242.             addEventListener(Event.ENTER_FRAME, onDrag);
  243.         }
  244.        
  245.         private function onDrag(e:Event):void {
  246.             //this make it so that that the panel's x position will move with the mouse
  247.             this.x = parent.mouseX - distanceX;
  248.         }
  249.     }
  250.    
  251. }
Advertisement
Add Comment
Please, Sign In to add comment