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

  1. package classes.basic.Button
  2. {
  3.    import classes.basic.Events.TFEvent;
  4.    import classes.basic.Sound.TFSound;
  5.    import flash.display.MovieClip;
  6.    import flash.events.MouseEvent;
  7.    
  8.    public class TFButton
  9.    {
  10.        
  11.       
  12.       protected var hitArea:Object;
  13.       
  14.       private var fxOver:TFSound;
  15.       
  16.       private var fxClick:TFSound;
  17.       
  18.       protected var movieClip:MovieClip;
  19.       
  20.       private var fxOut:TFSound;
  21.       
  22.       public var onEvent:Function;
  23.       
  24.       public function TFButton(param1:MovieClip, param2:Function)
  25.       {
  26.          super();
  27.          fxOver = null;
  28.          movieClip = param1;
  29.          updateFields();
  30.          onEvent = param2;
  31.          registerEvents();
  32.          if(onEvent != null)
  33.          {
  34.             onEvent(new TFEvent(TFEvent.EVENT_INIT,movieClip));
  35.          }
  36.       }
  37.       
  38.       public function enable() : *
  39.       {
  40.          hitArea.mouseEnabled = true;
  41.          if(movieClip.disabled != undefined)
  42.          {
  43.             movieClip.disabled.visible = false;
  44.             if(movieClip.out != undefined)
  45.             {
  46.                movieClip.out.visible = true;
  47.             }
  48.             if(movieClip.over != undefined)
  49.             {
  50.                movieClip.over.visible = false;
  51.             }
  52.             if(movieClip.down != undefined)
  53.             {
  54.                movieClip.down.visible = false;
  55.             }
  56.          }
  57.          if(onEvent != null)
  58.          {
  59.             onEvent(new TFEvent(TFEvent.EVENT_ENABLE,movieClip));
  60.          }
  61.       }
  62.       
  63.       public function setFxOver(param1:TFSound) : *
  64.       {
  65.          this.fxOver = param1;
  66.       }
  67.       
  68.       protected function onMCRollOver(param1:MouseEvent) : void
  69.       {
  70.          if(hitArea == null || hitArea.mouseEnabled == true)
  71.          {
  72.             if(movieClip.out != undefined)
  73.             {
  74.                movieClip.out.visible = false;
  75.             }
  76.             if(movieClip.over != undefined)
  77.             {
  78.                movieClip.over.visible = true;
  79.             }
  80.             if(movieClip.down != undefined)
  81.             {
  82.                movieClip.down.visible = false;
  83.             }
  84.             if(onEvent != null)
  85.             {
  86.                onEvent(new TFEvent(TFEvent.EVENT_MOUSEOVER,movieClip));
  87.             }
  88.             if(fxOver != null)
  89.             {
  90.                fxOver.play();
  91.             }
  92.          }
  93.          param1.updateAfterEvent();
  94.       }
  95.       
  96.       protected function onMCClick(param1:MouseEvent) : void
  97.       {
  98.          if(hitArea == null || hitArea.mouseEnabled == true)
  99.          {
  100.             if(movieClip.out != undefined)
  101.             {
  102.                movieClip.out.visible = false;
  103.             }
  104.             if(movieClip.over != undefined)
  105.             {
  106.                movieClip.over.visible = true;
  107.             }
  108.             if(onEvent != null)
  109.             {
  110.                onEvent(new TFEvent(TFEvent.EVENT_MOUSECLICK,movieClip));
  111.             }
  112.             if(fxClick != null)
  113.             {
  114.                fxClick.play();
  115.             }
  116.             param1.updateAfterEvent();
  117.          }
  118.       }
  119.       
  120.       public function setFxClick(param1:TFSound) : *
  121.       {
  122.          this.fxClick = param1;
  123.       }
  124.       
  125.       public function setFxOut(param1:TFSound) : *
  126.       {
  127.          this.fxOut = param1;
  128.       }
  129.       
  130.       protected function registerEvents() : *
  131.       {
  132.          hitArea.addEventListener(MouseEvent.ROLL_OVER,onMCRollOver,false,0,true);
  133.          hitArea.addEventListener(MouseEvent.ROLL_OUT,onMCRollOut,false,0,true);
  134.          hitArea.addEventListener(MouseEvent.CLICK,onMCClick,false,0,true);
  135.          hitArea.addEventListener(MouseEvent.MOUSE_DOWN,onMCDown,false,0,true);
  136.          hitArea.addEventListener(MouseEvent.MOUSE_UP,onMCUp,false,0,true);
  137.       }
  138.       
  139.       protected function updateFields() : *
  140.       {
  141.          if(movieClip.out != undefined)
  142.          {
  143.             movieClip.out.visible = true;
  144.          }
  145.          if(movieClip.over != undefined)
  146.          {
  147.             movieClip.over.visible = false;
  148.          }
  149.          if(movieClip.down != undefined)
  150.          {
  151.             movieClip.down.visible = false;
  152.          }
  153.          if(movieClip.disabled != undefined)
  154.          {
  155.             movieClip.disabled.visible = false;
  156.          }
  157.          if(movieClip.btnHitArea != null)
  158.          {
  159.             hitArea = movieClip.btnHitArea;
  160.          }
  161.          else
  162.          {
  163.             hitArea = movieClip;
  164.          }
  165.       }
  166.       
  167.       protected function onMCRollOut(param1:MouseEvent) : void
  168.       {
  169.          if(hitArea == null || hitArea.mouseEnabled == true)
  170.          {
  171.             if(movieClip.out != undefined)
  172.             {
  173.                movieClip.out.visible = true;
  174.             }
  175.             if(movieClip.over != undefined)
  176.             {
  177.                movieClip.over.visible = false;
  178.             }
  179.             if(movieClip.down != undefined)
  180.             {
  181.                movieClip.down.visible = false;
  182.             }
  183.             if(onEvent != null)
  184.             {
  185.                onEvent(new TFEvent(TFEvent.EVENT_MOUSEOUT,movieClip));
  186.             }
  187.             if(fxOut != null)
  188.             {
  189.                fxOut.play();
  190.             }
  191.          }
  192.          param1.updateAfterEvent();
  193.       }
  194.       
  195.       public function disable() : *
  196.       {
  197.          hitArea.mouseEnabled = false;
  198.          if(movieClip.disabled != undefined)
  199.          {
  200.             movieClip.disabled.visible = true;
  201.             if(movieClip.out != undefined)
  202.             {
  203.                movieClip.out.visible = false;
  204.             }
  205.          }
  206.          else if(movieClip.out != undefined)
  207.          {
  208.             movieClip.out.visible = true;
  209.          }
  210.          if(movieClip.over != undefined)
  211.          {
  212.             movieClip.over.visible = false;
  213.          }
  214.          if(movieClip.down != undefined)
  215.          {
  216.             movieClip.down.visible = false;
  217.          }
  218.          if(onEvent != null)
  219.          {
  220.             onEvent(new TFEvent(TFEvent.EVENT_DISABLE,movieClip));
  221.          }
  222.       }
  223.       
  224.       protected function onMCUp(param1:MouseEvent) : void
  225.       {
  226.          if(hitArea == null || hitArea.mouseEnabled == true)
  227.          {
  228.             if(movieClip.down != undefined)
  229.             {
  230.                if(movieClip.down is MovieClip == true && movieClip.down.currentFrame < 2)
  231.                {
  232.                   movieClip.down.visible = false;
  233.                }
  234.                if(movieClip.out != undefined)
  235.                {
  236.                   movieClip.out.visible = false;
  237.                }
  238.                if(movieClip.over != undefined)
  239.                {
  240.                   movieClip.over.visible = true;
  241.                }
  242.             }
  243.             if(onEvent != null)
  244.             {
  245.                onEvent(new TFEvent(TFEvent.EVENT_MOUSEUP,movieClip));
  246.             }
  247.          }
  248.          param1.updateAfterEvent();
  249.       }
  250.       
  251.       public function unregisterEvents() : *
  252.       {
  253.          hitArea.removeEventListener(MouseEvent.ROLL_OVER,onMCRollOver,false);
  254.          hitArea.removeEventListener(MouseEvent.ROLL_OUT,onMCRollOut,false);
  255.          hitArea.removeEventListener(MouseEvent.CLICK,onMCClick,false);
  256.          hitArea.removeEventListener(MouseEvent.MOUSE_DOWN,onMCDown,false);
  257.          hitArea.removeEventListener(MouseEvent.MOUSE_UP,onMCUp,false);
  258.       }
  259.       
  260.       protected function onMCDown(param1:MouseEvent) : void
  261.       {
  262.          if(hitArea == null || hitArea.mouseEnabled == true)
  263.          {
  264.             if(movieClip.down != undefined)
  265.             {
  266.                if(movieClip.out != undefined)
  267.                {
  268.                   movieClip.out.visible = false;
  269.                }
  270.                if(movieClip.over != undefined)
  271.                {
  272.                   movieClip.over.visible = false;
  273.                }
  274.                movieClip.down.visible = true;
  275.                if(movieClip.down is MovieClip == true && movieClip.down.totalFrames > 1)
  276.                {
  277.                   movieClip.down.gotoAndPlay(2);
  278.                }
  279.             }
  280.             if(onEvent != null)
  281.             {
  282.                onEvent(new TFEvent(TFEvent.EVENT_MOUSEDOWN,movieClip));
  283.             }
  284.          }
  285.          param1.updateAfterEvent();
  286.       }
  287.    }
  288. }
  289.