home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / kung_fu.swf / scripts / __Packages / com / KidFighting / objects / CEffect.as < prev    next >
Encoding:
Text File  |  2006-06-13  |  3.2 KB  |  130 lines

  1. class com.KidFighting.objects.CEffect extends com.KidFighting.objects.CObject
  2. {
  3.    var _twn;
  4.    var ani;
  5.    var visX;
  6.    var visY;
  7.    var type;
  8.    var owner;
  9.    var _eff_observer;
  10.    var _ch_observer;
  11.    var onMotionUpdated;
  12.    var onMotionStopped;
  13.    var performing;
  14.    var effStartFrame = -1;
  15.    function CEffect()
  16.    {
  17.       super();
  18.    }
  19.    function get looping()
  20.    {
  21.       return this._twn.looping;
  22.    }
  23.    function set looping(lp)
  24.    {
  25.       this._twn.looping = Boolean(lp);
  26.    }
  27.    function init($ani, twn, ch, x, y)
  28.    {
  29.       this.ani = $ani;
  30.       this._twn = new ds.transitions.Tween(null,"_currentframe",null,1,this.ani._totalframes,this.ani._totalframes);
  31.       this._twn.obj = this.ani;
  32.       this._twn.owner = this;
  33.       this.ani.gotoAndStop(1);
  34.       this.ani._visible = false;
  35.       this.visX = x;
  36.       this.visY = y;
  37.       this.ani.type = this.type;
  38.       this.ani.owner = this;
  39.       this.owner = ch;
  40.       this._eff_observer = ds.transitions.TweenObserver.observeTween(this._twn);
  41.       if(twn != null)
  42.       {
  43.          this._ch_observer = ds.transitions.TweenObserver.observeTween(twn);
  44.          this.onMotionUpdated = this.onCharacterMotionUpdated;
  45.          this.addCharacterListener(this);
  46.       }
  47.       else
  48.       {
  49.          this.start();
  50.       }
  51.       this.onMotionStopped = this.onEffectMotionFinished;
  52.    }
  53.    function onCharacterMotionUpdated(twn)
  54.    {
  55.       if(twn.obj._currentframe >= this.effStartFrame && this.effStartFrame != -1)
  56.       {
  57.          this.removeCharacterListener(this);
  58.          if(this.owner.status != "hurt" && this.owner.status != "cought" && this.owner.status != "thown" && this.owner.HP > 0)
  59.          {
  60.             this.start();
  61.          }
  62.          else
  63.          {
  64.             this.onEffectMotionFinished();
  65.          }
  66.       }
  67.    }
  68.    function onEffectMotionUpdated()
  69.    {
  70.    }
  71.    function onEffectMotionFinished(twn)
  72.    {
  73.       if(this._ch_observer)
  74.       {
  75.          this._ch_observer.unobserve();
  76.          this.removeCharacterListener(this);
  77.       }
  78.       this._eff_observer.unobserve();
  79.       if(this.effStartFrame != -1)
  80.       {
  81.          this.removeEffectListener(this);
  82.          this.ani._visible = false;
  83.       }
  84.       this.performing = false;
  85.       this.ani.owner = null;
  86.       this.destroy();
  87.    }
  88.    function start()
  89.    {
  90.       this.ani._x = this.visX;
  91.       this.ani._y = this.visY;
  92.       this.performing = true;
  93.       this.onMotionUpdated = this.onEffectMotionUpdated;
  94.       this.addEffectListener(this);
  95.       this.ani._visible = true;
  96.       this._twn.start();
  97.    }
  98.    function stop()
  99.    {
  100.       this._twn.stop();
  101.    }
  102.    function addCharacterListener(lsn)
  103.    {
  104.       this._ch_observer.addListener(lsn);
  105.    }
  106.    function removeCharacterListener(lsn)
  107.    {
  108.       this._ch_observer.removeListener(lsn);
  109.    }
  110.    function addEffectListener(lsn)
  111.    {
  112.       this._eff_observer.addListener(lsn);
  113.    }
  114.    function removeEffectListener(lsn)
  115.    {
  116.       this._eff_observer.removeListener(lsn);
  117.    }
  118.    function onPauseGame()
  119.    {
  120.       if(this._twn.isPlaying)
  121.       {
  122.          this._twn.pause();
  123.       }
  124.    }
  125.    function onResumeGame()
  126.    {
  127.       this._twn.resume();
  128.    }
  129. }
  130.