home *** CD-ROM | disk | FTP | other *** search
- package classes.basic.Button
- {
- import classes.basic.Events.TFEvent;
- import classes.basic.Sound.TFSound;
- import flash.display.MovieClip;
- import flash.events.MouseEvent;
-
- public class TFButton
- {
-
-
- protected var hitArea:Object;
-
- private var fxOver:TFSound;
-
- private var fxClick:TFSound;
-
- protected var movieClip:MovieClip;
-
- private var fxOut:TFSound;
-
- public var onEvent:Function;
-
- public function TFButton(param1:MovieClip, param2:Function)
- {
- super();
- fxOver = null;
- movieClip = param1;
- updateFields();
- onEvent = param2;
- registerEvents();
- if(onEvent != null)
- {
- onEvent(new TFEvent(TFEvent.EVENT_INIT,movieClip));
- }
- }
-
- public function enable() : *
- {
- hitArea.mouseEnabled = true;
- if(movieClip.disabled != undefined)
- {
- movieClip.disabled.visible = false;
- if(movieClip.out != undefined)
- {
- movieClip.out.visible = true;
- }
- if(movieClip.over != undefined)
- {
- movieClip.over.visible = false;
- }
- if(movieClip.down != undefined)
- {
- movieClip.down.visible = false;
- }
- }
- if(onEvent != null)
- {
- onEvent(new TFEvent(TFEvent.EVENT_ENABLE,movieClip));
- }
- }
-
- public function setFxOver(param1:TFSound) : *
- {
- this.fxOver = param1;
- }
-
- protected function onMCRollOver(param1:MouseEvent) : void
- {
- if(hitArea == null || hitArea.mouseEnabled == true)
- {
- if(movieClip.out != undefined)
- {
- movieClip.out.visible = false;
- }
- if(movieClip.over != undefined)
- {
- movieClip.over.visible = true;
- }
- if(movieClip.down != undefined)
- {
- movieClip.down.visible = false;
- }
- if(onEvent != null)
- {
- onEvent(new TFEvent(TFEvent.EVENT_MOUSEOVER,movieClip));
- }
- if(fxOver != null)
- {
- fxOver.play();
- }
- }
- param1.updateAfterEvent();
- }
-
- protected function onMCClick(param1:MouseEvent) : void
- {
- if(hitArea == null || hitArea.mouseEnabled == true)
- {
- if(movieClip.out != undefined)
- {
- movieClip.out.visible = false;
- }
- if(movieClip.over != undefined)
- {
- movieClip.over.visible = true;
- }
- if(onEvent != null)
- {
- onEvent(new TFEvent(TFEvent.EVENT_MOUSECLICK,movieClip));
- }
- if(fxClick != null)
- {
- fxClick.play();
- }
- param1.updateAfterEvent();
- }
- }
-
- public function setFxClick(param1:TFSound) : *
- {
- this.fxClick = param1;
- }
-
- public function setFxOut(param1:TFSound) : *
- {
- this.fxOut = param1;
- }
-
- protected function registerEvents() : *
- {
- hitArea.addEventListener(MouseEvent.ROLL_OVER,onMCRollOver,false,0,true);
- hitArea.addEventListener(MouseEvent.ROLL_OUT,onMCRollOut,false,0,true);
- hitArea.addEventListener(MouseEvent.CLICK,onMCClick,false,0,true);
- hitArea.addEventListener(MouseEvent.MOUSE_DOWN,onMCDown,false,0,true);
- hitArea.addEventListener(MouseEvent.MOUSE_UP,onMCUp,false,0,true);
- }
-
- protected function updateFields() : *
- {
- if(movieClip.out != undefined)
- {
- movieClip.out.visible = true;
- }
- if(movieClip.over != undefined)
- {
- movieClip.over.visible = false;
- }
- if(movieClip.down != undefined)
- {
- movieClip.down.visible = false;
- }
- if(movieClip.disabled != undefined)
- {
- movieClip.disabled.visible = false;
- }
- if(movieClip.btnHitArea != null)
- {
- hitArea = movieClip.btnHitArea;
- }
- else
- {
- hitArea = movieClip;
- }
- }
-
- protected function onMCRollOut(param1:MouseEvent) : void
- {
- if(hitArea == null || hitArea.mouseEnabled == true)
- {
- if(movieClip.out != undefined)
- {
- movieClip.out.visible = true;
- }
- if(movieClip.over != undefined)
- {
- movieClip.over.visible = false;
- }
- if(movieClip.down != undefined)
- {
- movieClip.down.visible = false;
- }
- if(onEvent != null)
- {
- onEvent(new TFEvent(TFEvent.EVENT_MOUSEOUT,movieClip));
- }
- if(fxOut != null)
- {
- fxOut.play();
- }
- }
- param1.updateAfterEvent();
- }
-
- public function disable() : *
- {
- hitArea.mouseEnabled = false;
- if(movieClip.disabled != undefined)
- {
- movieClip.disabled.visible = true;
- if(movieClip.out != undefined)
- {
- movieClip.out.visible = false;
- }
- }
- else if(movieClip.out != undefined)
- {
- movieClip.out.visible = true;
- }
- if(movieClip.over != undefined)
- {
- movieClip.over.visible = false;
- }
- if(movieClip.down != undefined)
- {
- movieClip.down.visible = false;
- }
- if(onEvent != null)
- {
- onEvent(new TFEvent(TFEvent.EVENT_DISABLE,movieClip));
- }
- }
-
- protected function onMCUp(param1:MouseEvent) : void
- {
- if(hitArea == null || hitArea.mouseEnabled == true)
- {
- if(movieClip.down != undefined)
- {
- if(movieClip.down is MovieClip == true && movieClip.down.currentFrame < 2)
- {
- movieClip.down.visible = false;
- }
- if(movieClip.out != undefined)
- {
- movieClip.out.visible = false;
- }
- if(movieClip.over != undefined)
- {
- movieClip.over.visible = true;
- }
- }
- if(onEvent != null)
- {
- onEvent(new TFEvent(TFEvent.EVENT_MOUSEUP,movieClip));
- }
- }
- param1.updateAfterEvent();
- }
-
- public function unregisterEvents() : *
- {
- hitArea.removeEventListener(MouseEvent.ROLL_OVER,onMCRollOver,false);
- hitArea.removeEventListener(MouseEvent.ROLL_OUT,onMCRollOut,false);
- hitArea.removeEventListener(MouseEvent.CLICK,onMCClick,false);
- hitArea.removeEventListener(MouseEvent.MOUSE_DOWN,onMCDown,false);
- hitArea.removeEventListener(MouseEvent.MOUSE_UP,onMCUp,false);
- }
-
- protected function onMCDown(param1:MouseEvent) : void
- {
- if(hitArea == null || hitArea.mouseEnabled == true)
- {
- if(movieClip.down != undefined)
- {
- if(movieClip.out != undefined)
- {
- movieClip.out.visible = false;
- }
- if(movieClip.over != undefined)
- {
- movieClip.over.visible = false;
- }
- movieClip.down.visible = true;
- if(movieClip.down is MovieClip == true && movieClip.down.totalFrames > 1)
- {
- movieClip.down.gotoAndPlay(2);
- }
- }
- if(onEvent != null)
- {
- onEvent(new TFEvent(TFEvent.EVENT_MOUSEDOWN,movieClip));
- }
- }
- param1.updateAfterEvent();
- }
- }
- }
-