home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 148 / MOBICLIC148.ISO / mac / DATA / DSS148 / DSS148_01 / DSS148_01.swf / scripts / dss148 / Relance.as < prev   
Text File  |  2012-10-16  |  2KB  |  78 lines

  1. package dss148
  2. {
  3.    import flash.events.TimerEvent;
  4.    import flash.utils.Timer;
  5.    
  6.    public class Relance
  7.    {
  8.        
  9.       
  10.       private var timer:Timer;
  11.       
  12.       public var method:Function = null;
  13.       
  14.       public var isSleeping:Boolean = false;
  15.       
  16.       public function Relance(param1:Number = 0, param2:Function = null)
  17.       {
  18.          super();
  19.          this.method = param2;
  20.          this.timer = new Timer(param1,1);
  21.       }
  22.       
  23.       public function set delai(param1:Number) : void
  24.       {
  25.          this.timer.delay = param1;
  26.       }
  27.       
  28.       public function start() : void
  29.       {
  30.          this.timer.addEventListener(TimerEvent.TIMER_COMPLETE,this.timerHandler);
  31.          this.timer.reset();
  32.          this.timer.start();
  33.       }
  34.       
  35.       public function stop() : void
  36.       {
  37.          this.timer.removeEventListener(TimerEvent.TIMER_COMPLETE,this.timerHandler);
  38.          this.timer.stop();
  39.       }
  40.       
  41.       private function timerHandler(param1:TimerEvent) : void
  42.       {
  43.          this.stop();
  44.          this.method(this.methodCallback);
  45.       }
  46.       
  47.       public function methodCallback() : void
  48.       {
  49.          this.start();
  50.       }
  51.       
  52.       public function sleep() : void
  53.       {
  54.          if(this.timer.running)
  55.          {
  56.             this.timer.stop();
  57.             this.isSleeping = true;
  58.          }
  59.       }
  60.       
  61.       public function wake() : void
  62.       {
  63.          if(this.isSleeping)
  64.          {
  65.             this.timer.start();
  66.             this.isSleeping = false;
  67.          }
  68.       }
  69.       
  70.       public function destroy() : void
  71.       {
  72.          this.stop();
  73.          this.timer = null;
  74.          this.method = null;
  75.       }
  76.    }
  77. }
  78.