home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / beauty_resort.swf / scripts / classes / basic / Button / TFSwitchButton.as < prev    next >
Encoding:
Text File  |  2008-09-04  |  2.8 KB  |  113 lines

  1. package classes.basic.Button
  2. {
  3.    import classes.basic.Events.TFEvent;
  4.    import classes.basic.MovieClip.*;
  5.    import flash.display.MovieClip;
  6.    
  7.    public class TFSwitchButton extends TFButton
  8.    {
  9.        
  10.       
  11.       private var eventHandler:Function;
  12.       
  13.       private var over:Boolean;
  14.       
  15.       public function TFSwitchButton(param1:MovieClip, param2:Function)
  16.       {
  17.          this.over = false;
  18.          this.eventHandler = param2;
  19.          super(param1,onBtnEvent);
  20.       }
  21.       
  22.       private function update() : *
  23.       {
  24.          if(movieClip.out != undefined)
  25.          {
  26.             if(over)
  27.             {
  28.                movieClip.out.visible = false;
  29.             }
  30.             else
  31.             {
  32.                movieClip.out.visible = true;
  33.             }
  34.          }
  35.          if(movieClip.over != undefined)
  36.          {
  37.             if(over)
  38.             {
  39.                movieClip.over.visible = true;
  40.             }
  41.             else
  42.             {
  43.                movieClip.over.visible = false;
  44.             }
  45.          }
  46.          if(movieClip.down != undefined)
  47.          {
  48.             movieClip.down.visible = false;
  49.          }
  50.          if(movieClip.disabled != undefined)
  51.          {
  52.             movieClip.disabled.visible = false;
  53.          }
  54.       }
  55.       
  56.       private function onLoadFrame() : *
  57.       {
  58.          movieClip.stop();
  59.          update();
  60.       }
  61.       
  62.       protected function onBtnEvent(param1:TFEvent) : *
  63.       {
  64.          switch(param1.event)
  65.          {
  66.             case TFEvent.EVENT_MOUSECLICK:
  67.                if(movieClip.currentFrame == 1)
  68.                {
  69.                   off();
  70.                }
  71.                else
  72.                {
  73.                   on();
  74.                }
  75.                break;
  76.             case TFEvent.EVENT_INIT:
  77.                break;
  78.             case TFEvent.EVENT_MOUSEOUT:
  79.                over = false;
  80.                break;
  81.             case TFEvent.EVENT_MOUSEOVER:
  82.                over = true;
  83.                break;
  84.             default:
  85.                if(eventHandler != null)
  86.                {
  87.                   eventHandler(param1);
  88.                }
  89.          }
  90.       }
  91.       
  92.       public function on() : *
  93.       {
  94.          movieClip.gotoAndStop("on");
  95.          TFMovieClip.addLabelScript(movieClip,"on",onLoadFrame);
  96.          if(eventHandler != null)
  97.          {
  98.             eventHandler(new TFEvent(TFEvent.EVENT_ON,movieClip));
  99.          }
  100.       }
  101.       
  102.       public function off() : *
  103.       {
  104.          movieClip.gotoAndStop("off");
  105.          TFMovieClip.addLabelScript(movieClip,"off",onLoadFrame);
  106.          if(eventHandler != null)
  107.          {
  108.             eventHandler(new TFEvent(TFEvent.EVENT_OFF,movieClip));
  109.          }
  110.       }
  111.    }
  112. }
  113.