Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package code {
- import flash.display.MovieClip;
- import flash.events.MouseEvent;
- import flash.events.Event;
- import flash.geom.Point;
- public class SubMenuPanel extends MovieClip {
- private var subMenuButton:SubMenuButton;
- private var subMenuButtons:Array = new Array();
- private var distanceX:Number;
- private var selectedButton:SubMenuButton;
- private var currentButton:SubMenuButton;
- private var tempButton:SubMenuButton;
- public var myDoc:Document;
- public function SubMenuPanel(buttonCount:Number,buttonNames:Array) {
- // constructor code
- tempButton = new SubMenuButton();
- myDoc = Document.DOCUMENT;
- for(var i:int=0; i<buttonCount; i++)
- {
- //trace("scorebutton count: " + i);
- subMenuButton = new SubMenuButton();
- subMenuButton.name = buttonNames[i];
- addChild(subMenuButton);
- subMenuButton.x=(subMenuButtons.length)*177.95+40;
- subMenuButton.subMenuBtnTxt.text = buttonNames[i];
- subMenuButtons.push(subMenuButton);
- }
- addEventListener(MouseEvent.MOUSE_DOWN, onMD);
- addEventListener(MouseEvent.MOUSE_UP, onMU);
- }
- private function onMU(e:MouseEvent):void
- {
- //trace("Mouse Up tehehehahahaha");
- removeEventListener(Event.ENTER_FRAME, onDrag);
- //var myPointer:Number;
- //myPointer = myDoc.pointer.x;
- var globalPointerPos:Point = myDoc.pointer.parent.localToGlobal(new Point(myDoc.pointer.x, myDoc.pointer.y));
- for (var i:Number = 0; i < subMenuButtons.length; i++ ) {
- var globalButtonPos:Point = this.localToGlobal(new Point(subMenuButtons[i].x, subMenuButtons[i].y));
- if (globalButtonPos.x > globalPointerPos.x)
- {
- break;
- }
- }
- i = i - 1;
- if (i < 0)
- {
- i = 0;
- }
- tempButton = subMenuButtons[i];
- trace(tempButton.name);
- //Point Shop
- if(tempButton.name == "Discounts")
- {
- trace(tempButton.name);
- myDoc.addSubMenu2(PointShopMenu,"02");
- }
- if(tempButton.name == "Products")
- {
- myDoc.addSubMenu2(PointShopMenu,"01");
- }
- if(tempButton.name == "Promotions")
- {
- myDoc.addSubMenu2(PointShopMenu,"03");
- }
- if(tempButton.name == "Cart")
- {
- myDoc.addSubMenu2(PointShopMenu,"04");
- }
- //Score Card Sub Menu
- if(tempButton.name == "Personal Scores")
- {
- trace(tempButton.name);
- myDoc.addSubMenu2(ScoresMenu,"personal");
- }
- if(tempButton.name == "High Scores")
- {
- myDoc.addSubMenu2(ScoresMenu,"highscores");
- }
- if(tempButton.name == "Top Players")
- {
- myDoc.addSubMenu2(ScoresMenu,"topPlayers");
- }
- //Tests Sub Menu
- if(tempButton.name == "Current Tests")
- {
- trace(tempButton.name);
- myDoc.addSubMenu2(TestsMenu,"currentTest");
- }
- if(tempButton.name == "Tests")
- {
- myDoc.addSubMenu2(TestsMenu,"tests");
- }
- if(tempButton.name == "Recent Tests")
- {
- myDoc.addSubMenu2(TestsMenu,"recentTests");
- }
- //Tests Sub Menu
- if(tempButton.name == "Address")
- {
- trace(tempButton.name);
- myDoc.addSubMenu2(AccountMenu,"address");
- }
- if(tempButton.name == "Profile")
- {
- myDoc.addSubMenu2(AccountMenu,"profile");
- }
- if(tempButton.name == "Preferences")
- {
- myDoc.addSubMenu2(AccountMenu,"preferences");
- }
- //Playbook Sub Menu & Mini Menu
- if(tempButton.name == "BasketBall")
- {
- myDoc.addPlaybookSubMenu(PlaybookSportSubMenu);
- //trying to change this
- PlaybookSportSubMenu.aClip.gotoAndStop(01);
- }
- if(tempButton.name == "Baseball")
- {
- myDoc.addPlaybookSubMenu(PlaybookSportSubMenu);
- //trying to change this
- PlaybookSportSubMenu.aClip.gotoAndStop(05);
- }
- if(tempButton.name == "Football")
- {
- myDoc.addPlaybookSubMenu(PlaybookSportSubMenu);
- //trying to change this
- PlaybookSportSubMenu.aClip.gotoAndStop(10);
- }
- if(tempButton.name == "Hockey")
- {
- myDoc.addPlaybookSubMenu(PlaybookSportSubMenu);
- }
- if(tempButton.name == "Golf")
- {
- myDoc.addPlaybookSubMenu(PlaybookSportSubMenu);
- }
- if(tempButton.name == "Soccer")
- {
- myDoc.addPlaybookSubMenu(PlaybookSportSubMenu);
- }
- var globalTempButtonPos:Point = this.localToGlobal(new Point(tempButton.x, tempButton.y));
- var tempButtonCenterX:Number = globalTempButtonPos.x + tempButton.width/2;
- this.x = this.x + (globalPointerPos.x - tempButtonCenterX);
- if (selectedButton != null)
- {
- //selectedButton.highlight_mc.visible=false;
- //selectedButton.highlight_mc.y=-1;
- }
- selectedButton = tempButton;
- //selectedButton.highlight_mc.visible=true;
- //selectedButton.highlight_mc.y=-1;
- currentButton = selectedButton;
- }
- private function onMD(e:MouseEvent):void
- {
- //trace(currentButton);
- //i'm subtracting panel's coordinate from the mouse coordinate to save it's number as the distanceX
- //this will create a drag because if the distance isn't the same, the object wont drag with the mouse
- distanceX = parent.mouseX - this.x;
- addEventListener(Event.ENTER_FRAME, onDrag);
- }
- private function onDrag(e:Event):void {
- //this make it so that that the panel's x position will move with the mouse
- this.x = parent.mouseX - distanceX;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment