missEmm

SubMenuPanel.as

Apr 30th, 2011
74
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.MouseEvent;
  5.     import flash.events.Event;
  6.     import flash.geom.Point;
  7.    
  8.     public class SubMenuPanel extends MovieClip {
  9.         private var subMenuButton:SubMenuButton;
  10.         private var subMenuButtons:Array = new Array();
  11.         private var distanceX:Number;
  12.         private var selectedButton:SubMenuButton;
  13.         private var currentButton:SubMenuButton;
  14.         private var tempButton:SubMenuButton;
  15.  
  16.        
  17.         public var myDoc:Document;
  18.        
  19.         public function SubMenuPanel(buttonCount:Number,buttonNames:Array) {
  20.             // constructor code
  21.             tempButton = new SubMenuButton();
  22.            
  23.  
  24.             myDoc = Document.DOCUMENT;
  25.            
  26.             for(var i:int=0; i<buttonCount; i++)
  27.             {
  28.                
  29.                 //trace("scorebutton count: " + i);
  30.                 subMenuButton = new SubMenuButton();
  31.                 subMenuButton.name = buttonNames[i];
  32.                 addChild(subMenuButton);
  33.                 subMenuButton.x=(subMenuButtons.length)*177.95+40;
  34.                 subMenuButton.subMenuBtnTxt.text = buttonNames[i];
  35.                 subMenuButtons.push(subMenuButton);
  36.                
  37.             }
  38.            
  39.            
  40.             addEventListener(MouseEvent.MOUSE_DOWN, onMD);
  41.             addEventListener(MouseEvent.MOUSE_UP, onMU);
  42.         }
  43.        
  44.         private function onMU(e:MouseEvent):void
  45.         {
  46.             //trace("Mouse Up tehehehahahaha");
  47.            
  48.             removeEventListener(Event.ENTER_FRAME, onDrag);
  49.             //var myPointer:Number;
  50.             //myPointer = myDoc.pointer.x;
  51.             var globalPointerPos:Point = myDoc.pointer.parent.localToGlobal(new Point(myDoc.pointer.x, myDoc.pointer.y));
  52.            
  53.             for (var i:Number = 0; i < subMenuButtons.length; i++ ) {
  54.                 var globalButtonPos:Point = this.localToGlobal(new Point(subMenuButtons[i].x, subMenuButtons[i].y));
  55.                 if (globalButtonPos.x > globalPointerPos.x)
  56.                 {
  57.  
  58.                     break;
  59.                 }
  60.             }
  61.            
  62.             i = i - 1;
  63.             if (i < 0)
  64.             {
  65.                 i = 0;
  66.             }
  67.            
  68.             tempButton = subMenuButtons[i];
  69.            
  70.             trace(tempButton.name);
  71.            
  72.             //Point Shop
  73.            
  74.             if(tempButton.name == "Discounts")
  75.             {
  76.                 trace(tempButton.name);
  77.                 myDoc.addSubMenu2(PointShopMenu,"02");
  78.             }
  79.             if(tempButton.name == "Products")
  80.             {
  81.                 myDoc.addSubMenu2(PointShopMenu,"01");
  82.             }
  83.             if(tempButton.name == "Promotions")
  84.             {
  85.                 myDoc.addSubMenu2(PointShopMenu,"03");
  86.             }
  87.             if(tempButton.name == "Cart")
  88.             {
  89.                 myDoc.addSubMenu2(PointShopMenu,"04");
  90.             }
  91.            
  92.             //Score Card Sub Menu
  93.            
  94.             if(tempButton.name == "Personal Scores")
  95.             {
  96.                 trace(tempButton.name);
  97.                 myDoc.addSubMenu2(ScoresMenu,"personal");
  98.             }
  99.             if(tempButton.name == "High Scores")
  100.             {
  101.                 myDoc.addSubMenu2(ScoresMenu,"highscores");
  102.             }
  103.             if(tempButton.name == "Top Players")
  104.             {
  105.                 myDoc.addSubMenu2(ScoresMenu,"topPlayers");
  106.             }
  107.            
  108.            
  109.             //Tests Sub Menu
  110.            
  111.             if(tempButton.name == "Current Tests")
  112.             {
  113.                 trace(tempButton.name);
  114.                 myDoc.addSubMenu2(TestsMenu,"currentTest");
  115.             }
  116.             if(tempButton.name == "Tests")
  117.             {
  118.                 myDoc.addSubMenu2(TestsMenu,"tests");
  119.             }
  120.             if(tempButton.name == "Recent Tests")
  121.             {
  122.                 myDoc.addSubMenu2(TestsMenu,"recentTests");
  123.             }
  124.            
  125.             //Tests Sub Menu
  126.            
  127.             if(tempButton.name == "Address")
  128.             {
  129.                 trace(tempButton.name);
  130.                 myDoc.addSubMenu2(AccountMenu,"address");
  131.             }
  132.             if(tempButton.name == "Profile")
  133.             {
  134.                 myDoc.addSubMenu2(AccountMenu,"profile");
  135.             }
  136.             if(tempButton.name == "Preferences")
  137.             {
  138.                 myDoc.addSubMenu2(AccountMenu,"preferences");
  139.             }
  140.            
  141.             //Playbook Sub Menu & Mini Menu
  142.            
  143.             if(tempButton.name == "BasketBall")
  144.             {
  145.                 myDoc.addPlaybookSubMenu(PlaybookSportSubMenu);
  146.                
  147.                 //trying to change this
  148.                 PlaybookSportSubMenu.aClip.gotoAndStop(01);
  149.             }
  150.             if(tempButton.name == "Baseball")
  151.             {
  152.                 myDoc.addPlaybookSubMenu(PlaybookSportSubMenu);
  153.                
  154.                                 //trying to change this
  155.  
  156.                                 PlaybookSportSubMenu.aClip.gotoAndStop(05);
  157.  
  158.             }
  159.             if(tempButton.name == "Football")
  160.             {
  161.                 myDoc.addPlaybookSubMenu(PlaybookSportSubMenu);
  162.                
  163.                                 //trying to change this
  164.  
  165.                                 PlaybookSportSubMenu.aClip.gotoAndStop(10);
  166.  
  167.             }
  168.             if(tempButton.name == "Hockey")
  169.             {
  170.                 myDoc.addPlaybookSubMenu(PlaybookSportSubMenu);
  171.             }
  172.             if(tempButton.name == "Golf")
  173.             {
  174.                 myDoc.addPlaybookSubMenu(PlaybookSportSubMenu);
  175.             }
  176.             if(tempButton.name == "Soccer")
  177.             {
  178.                 myDoc.addPlaybookSubMenu(PlaybookSportSubMenu);
  179.             }
  180.                
  181.            
  182.            
  183.             var globalTempButtonPos:Point = this.localToGlobal(new Point(tempButton.x, tempButton.y));
  184.             var tempButtonCenterX:Number = globalTempButtonPos.x + tempButton.width/2;
  185.             this.x = this.x + (globalPointerPos.x - tempButtonCenterX);
  186.             if (selectedButton != null)
  187.             {
  188.                 //selectedButton.highlight_mc.visible=false;
  189.                 //selectedButton.highlight_mc.y=-1;
  190.  
  191.             }
  192.             selectedButton = tempButton;
  193.             //selectedButton.highlight_mc.visible=true;            
  194.             //selectedButton.highlight_mc.y=-1;
  195.            
  196.             currentButton = selectedButton;
  197.  
  198.         }
  199.        
  200.        
  201.         private function onMD(e:MouseEvent):void
  202.         {          
  203.            
  204.             //trace(currentButton);
  205.            
  206.             //i'm subtracting panel's coordinate from the mouse coordinate to save it's number as the distanceX
  207.             //this will create a drag because if the distance isn't the same, the object wont drag with the mouse
  208.             distanceX = parent.mouseX - this.x;
  209.             addEventListener(Event.ENTER_FRAME, onDrag);
  210.         }
  211.        
  212.         private function onDrag(e:Event):void {
  213.             //this make it so that that the panel's x position will move with the mouse
  214.             this.x = parent.mouseX - distanceX;
  215.         }
  216.     }
  217.    
  218. }
Advertisement
Add Comment
Please, Sign In to add comment