Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package code {
- import flash.display.MovieClip;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.geom.Point;
- public class Panel extends MovieClip {
- public var distanceX:Number = 0;
- public var button:MainMenuButton;
- public var buttons:Array = new Array();
- public var myDoc:Document;
- private var selectedButton:MainMenuButton;
- public var buttonNames:Array = new Array();
- public var currentName:String = new String();
- public var currentButton:MainMenuButton;
- public var previousSubMenu:SubMenu;
- public var currentSubMenu:SubMenu;
- public function Panel(aDoc:Document) {
- // constructor code
- buttonNames.push("ScoreCard","Point Shop","Search","Playbook","Testing","Account");
- myDoc = aDoc;
- x= -200;
- for(var i:int=0; i<6; i++)
- {
- button = new MainMenuButton();
- addChild(button);
- button.x=(buttons.length)*85+175;
- buttons.push(button);
- button.btnName.text = buttonNames[i];
- button.name= buttonNames[i];
- }
- 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 < buttons.length; i++ ) {
- var globalButtonPos:Point = this.localToGlobal(new Point(buttons[i].x, buttons[i].y));
- if (globalButtonPos.x > globalPointerPos.x)
- {
- break;
- }
- }
- i = i - 1;
- if (i < 0)
- {
- i = 0;
- }
- var tempButton:MainMenuButton = buttons[i];
- trace(tempButton.name);
- 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;
- //subMenuSelection()
- }
- //public function subMenuSelection():void
- // {
- // var ScoreCardSubMenu:SubMenu = new SubMenu();
- // currentSubMenu = ScoreCardSubMenu;
- //
- //
- // if(currentButton.name == "ScoreCard"){
- //
- // //currentButton.onSearchBtn();
- // currentSubMenu = previousSubMenu;
- // removeChild(previousSubMenu);
- // trace("removed");
- //
- // trace("Search button selection");
- // //var ScoreCardSubMenu:SubMenu = new SubMenu();
- // addChild(ScoreCardSubMenu);
- // ScoreCardSubMenu.x=-150;
- // ScoreCardSubMenu.y=60;
- // if(currentSubMenu != null)
- // /*{
- // currentSubMenu = previousSubMenu;
- // removeChild(previousSubMenu);
- // trace("removed");
- //
- // }*/
- // currentSubMenu=SearchSubMenu;
- //
- // }
- // else if(currentButton.name == "Point Shop")
- // {
- // //currentButton.onPointShopBtn();
- // trace("Pointshop button selection");
- // currentSubMenu = previousSubMenu;
- // removeChild(previousSubMenu);
- // trace("removed");
- //
- // var PointShopSubMenu:SubMenu = new SubMenu;
- // addChild(PointShopSubMenu);
- // PointShopSubMenu.x=-150;
- // PointShopSubMenu.y=60;
- // /*if(currentSubMenu != null)
- // {
- // currentSubMenu = previousSubMenu;
- // removeChild(previousSubMenu);
- // trace("removed");
- //
- // }*/
- // currentSubMenu=PointShopSubMenu;
- //
- //
- //
- // }
- // else if(currentButton.name == "Search")
- // {
- // //currentButton.onScorecardBtn();
- // currentSubMenu = previousSubMenu;
- // removeChild(previousSubMenu);
- // trace("removed");
- // trace("ScoreCard button selection");
- // var SearchSubMenu:SubMenu = new SubMenu;
- // addChild(SearchSubMenu);
- // SearchSubMenu.x=-150;
- // SearchSubMenu.y=60;
- // /*if(currentSubMenu != null)
- // {
- // currentSubMenu = previousSubMenu;
- // removeChild(previousSubMenu);
- // trace("removed");
- //
- // }*/
- //
- // currentSubMenu = SearchSubMenu;
- //
- // }
- // else if(currentButton.name == "Testing")
- // {
- // //currentButton.onTestingBtn();
- // currentSubMenu = previousSubMenu;
- // removeChild(previousSubMenu);
- // trace("removed");
- // trace("Playbook button selection");
- // var TestingSubMenu:SubMenu = new SubMenu;
- // addChild(TestingSubMenu);
- // TestingSubMenu.x=-150;
- // TestingSubMenu.y=60;
- // /*if(currentSubMenu != null)
- // {
- // currentSubMenu = previousSubMenu;
- // removeChild(previousSubMenu);
- // trace("removed");
- //
- // }*/
- // currentSubMenu = TestingSubMenu;
- //
- // }
- // else if(currentButton.name == "Playbook")
- // {
- // //currentButton.onPlaybookBtn();
- // currentSubMenu = previousSubMenu;
- // removeChild(previousSubMenu);
- // trace("removed");
- // trace("Playbook button selection");
- // var PlaybookSubMenu:SubMenu = new SubMenu;
- // addChild(PlaybookSubMenu);
- // PlaybookSubMenu.x=-150;
- // PlaybookSubMenu.y=60;
- // /*if(currentSubMenu != null)
- // {
- // currentSubMenu = previousSubMenu;
- // removeChild(previousSubMenu);
- // trace("removed");
- //
- // }*/
- // currentSubMenu = PlaybookSubMenu;
- //
- // }
- //
- // else
- // {
- // //currentButton.onAccountBtn();
- // currentSubMenu = previousSubMenu;
- // removeChild(previousSubMenu);
- // trace("removed");
- // trace("account button selection");
- // var AccountSubMenu:SubMenu = new SubMenu;
- // addChild(AccountSubMenu);
- // AccountSubMenu.x=-150;
- // AccountSubMenu.y=60;
- // /*if(currentSubMenu != null)
- // {
- // currentSubMenu = previousSubMenu;
- // removeChild(previousSubMenu);
- // trace("removed");
- // }*/
- // currentSubMenu = AccountSubMenu;
- //
- // }
- //
- // }
- private function onMD(e:MouseEvent):void
- {
- //trace(currentButton);
- if(currentButton != null)
- {
- currentButton.highlight_mc.visible=false;
- }
- trace("MOUSE DOWN WHOAHAHAHAHH");
- //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