home *** CD-ROM | disk | FTP | other *** search
- package classes.graphical.controls.buttons
- {
- import classes.dispatchers.ButtonsEvents;
- import classes.dispatchers.GameDispatcher;
- import classes.dispatchers.MouseEventDispatcher;
- import classes.dispatchers.MyMouseEvent;
- import flash.display.MovieClip;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.media.SoundChannel;
- import game.SoundManager;
- import game.ThisGameManager;
- import main.GameManager;
-
- public class GenericButton extends MovieClip
- {
-
-
- private var locked:Boolean;
-
- private var clicked:Boolean;
-
- public var hit_areaaaaa:MovieClip;
-
- internal var hit:MovieClip;
-
- internal var mouseChannel:SoundChannel;
-
- internal var sManager:SoundManager;
-
- private var over:Boolean;
-
- public function GenericButton()
- {
- mouseChannel = new SoundChannel();
- super();
- sManager = ThisGameManager.getInstance().soundManager;
- this.buttonMode = true;
- clicked = false;
- over = false;
- locked = false;
- mouseChildren = false;
- addEventListener(MouseEvent.CLICK,onClick);
- addEventListener(MouseEvent.ROLL_OVER,onRollingOver);
- addEventListener(MouseEvent.ROLL_OUT,onRollingOut);
- addEventListener(MouseEvent.MOUSE_DOWN,onMouseIsDown);
- addEventListener(MouseEvent.MOUSE_UP,onMouseIsUp);
- addEventListener(Event.REMOVED_FROM_STAGE,cleanUp);
- GameDispatcher.buttonsDispatcher.addEventListener(ButtonsEvents.BUTTONS_UNLOCKED,refreshButton);
- GameDispatcher.mouseDispatcher.addEventListener(MouseEventDispatcher.BUTTON_PRESSED,unclickButton);
- goToLabel("off");
- }
-
- protected function onRollingOut(param1:MouseEvent) : void
- {
- over = false;
- if(GameManager.getInstance().AreButtonsEnabled && !locked)
- {
- if(currentLabel != "out")
- {
- goToLabel("out");
- locked = true;
- }
- }
- }
-
- protected function goToLabel(param1:String) : void
- {
- var doesLabelExist:Boolean = false;
- var i:Number = NaN;
- var e:Error = null;
- var destinationLabel:String = param1;
- doesLabelExist = false;
- try
- {
- i = 0;
- while(i < currentLabels.length)
- {
- if(currentLabels[i].name == destinationLabel)
- {
- doesLabelExist = true;
- }
- i++;
- }
- if(!doesLabelExist)
- {
- e = new Error("there is no label with the name >" + destinationLabel + "< in the button with instance name >" + this.name + "<");
- throw e;
- }
- gotoAndPlay(destinationLabel);
- }
- catch(e:Error)
- {
- }
- }
-
- protected function onRollingOver(param1:MouseEvent) : void
- {
- over = true;
- if(GameManager.getInstance().AreButtonsEnabled)
- {
- if(clicked && param1.buttonDown)
- {
- goToLabel("click");
- }
- else if(!clicked && !locked)
- {
- clicked = false;
- goToLabel("on");
- locked = true;
- mouseChannel.stop();
- if(!ThisGameManager.getInstance().mute)
- {
- mouseChannel = sManager.mOver.play();
- }
- }
- }
- }
-
- protected function onMouseIsDown(param1:MouseEvent) : void
- {
- if(GameManager.getInstance().AreButtonsEnabled)
- {
- clicked = true;
- GameDispatcher.mouseDispatcher.buttonPressed(this);
- goToLabel("click");
- }
- }
-
- protected function unlockButton() : void
- {
- locked = false;
- refreshButton(new Event(""));
- }
-
- protected function unclickButton(param1:MyMouseEvent) : *
- {
- if(param1.callerObject != this)
- {
- this.clicked = false;
- }
- }
-
- protected function onMouseIsUp(param1:MouseEvent) : void
- {
- if(GameManager.getInstance().AreButtonsEnabled && clicked)
- {
- clicked = false;
- goToLabel("off");
- }
- GameDispatcher.mouseDispatcher.buttonPressed(this);
- }
-
- protected function cleanUp(param1:Event) : *
- {
- removeEventListener(MouseEvent.CLICK,onClick);
- removeEventListener(MouseEvent.ROLL_OVER,onRollingOver);
- removeEventListener(MouseEvent.ROLL_OUT,onRollingOut);
- removeEventListener(MouseEvent.MOUSE_DOWN,onMouseIsDown);
- removeEventListener(MouseEvent.MOUSE_UP,onMouseIsUp);
- removeEventListener(Event.REMOVED_FROM_STAGE,cleanUp);
- GameDispatcher.buttonsDispatcher.removeEventListener(ButtonsEvents.BUTTONS_UNLOCKED,refreshButton);
- GameDispatcher.mouseDispatcher.removeEventListener(MouseEventDispatcher.BUTTON_PRESSED,unclickButton);
- }
-
- protected function onClick(param1:MouseEvent) : void
- {
- if(GameManager.getInstance().AreButtonsEnabled)
- {
- }
- }
-
- protected function refreshButton(param1:Event) : void
- {
- if(over && this.currentLabel != "on" && !clicked)
- {
- goToLabel("on");
- locked = true;
- }
- if(!over && this.currentLabel != "off" && !clicked)
- {
- goToLabel("out");
- locked = true;
- }
- }
- }
- }
-