home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / Beez.swf / scripts / core / bonuses / AbstractBonus.as next >
Encoding:
Text File  |  2008-09-03  |  2.1 KB  |  81 lines

  1. package core.bonuses
  2. {
  3.    import core.BonusesManager;
  4.    import core.CoreEngine;
  5.    import core.events.CoreEvent;
  6.    import flash.events.EventDispatcher;
  7.    import flash.media.Sound;
  8.    
  9.    public class AbstractBonus extends EventDispatcher
  10.    {
  11.        
  12.       
  13.       protected var activateTime:int;
  14.       
  15.       protected var engine:CoreEngine;
  16.       
  17.       public var num:uint;
  18.       
  19.       protected var lifeTime:int;
  20.       
  21.       public var timeLeft:int;
  22.       
  23.       public var isGood:Boolean;
  24.       
  25.       protected var sndActivate:Sound;
  26.       
  27.       public function AbstractBonus(isGood:Boolean)
  28.       {
  29.          super();
  30.          this.isGood = isGood;
  31.          init();
  32.       }
  33.       
  34.       protected function updateHandler(e:CoreEvent) : void
  35.       {
  36.          var time:int = e.data as int;
  37.          timeLeft = lifeTime + activateTime - time;
  38.          if(timeLeft <= 0)
  39.          {
  40.             deactivate();
  41.          }
  42.       }
  43.       
  44.       protected function deactivate() : void
  45.       {
  46.          engine.dispatcher.removeEventListener(CoreEvent.UPDATE,updateHandler);
  47.          dispatchEvent(new CoreEvent(BonusesManager.BONUS_DEACTIVATE,this));
  48.       }
  49.       
  50.       protected function init() : void
  51.       {
  52.          engine = CoreEngine.getInstance();
  53.          lifeTime = 40 * 3;
  54.          num = 1;
  55.          initSounds();
  56.          engine.dispatcher.addEventListener(CoreEvent.DESTROY,destroyHandler);
  57.       }
  58.       
  59.       protected function destroyHandler(e:CoreEvent) : void
  60.       {
  61.          engine.dispatcher.removeEventListener(CoreEvent.UPDATE,updateHandler);
  62.          engine.dispatcher.removeEventListener(CoreEvent.DESTROY,destroyHandler);
  63.       }
  64.       
  65.       public function activate(activateTime:Number) : void
  66.       {
  67.          this.activateTime = activateTime;
  68.          if(sndActivate)
  69.          {
  70.             engine.sndChannel = sndActivate.play(0,0,engine.sndTransform);
  71.          }
  72.          engine.dispatcher.addEventListener(CoreEvent.UPDATE,updateHandler);
  73.       }
  74.       
  75.       protected function initSounds() : void
  76.       {
  77.          sndActivate = null;
  78.       }
  79.    }
  80. }
  81.