home *** CD-ROM | disk | FTP | other *** search
/ ftp.novell.com / 2014.06.ftp.novell.com.tar / ftp.novell.com / forge / camtasia.msi / Cabs.w1.cab / camtasia_player_ext.swf9 / scripts / __Packages / mx / effects / Tween.as
Text File  |  2009-08-17  |  4KB  |  132 lines

  1. class mx.effects.Tween extends Object
  2. {
  3.    static var ActiveTweens = new Array();
  4.    static var Interval = 10;
  5.    static var Dispatcher = new Object();
  6.    var duration = 3000;
  7.    function Tween(listenerObj, init, end, dur)
  8.    {
  9.       super();
  10.       if(listenerObj == undefined)
  11.       {
  12.          return undefined;
  13.       }
  14.       if(typeof init != "number")
  15.       {
  16.          this.arrayMode = true;
  17.       }
  18.       this.listener = listenerObj;
  19.       this.initVal = init;
  20.       this.endVal = end;
  21.       if(dur != undefined)
  22.       {
  23.          this.duration = dur;
  24.       }
  25.       this.startTime = getTimer();
  26.       if(this.duration == 0)
  27.       {
  28.          this.endTween();
  29.       }
  30.       else
  31.       {
  32.          mx.effects.Tween.AddTween(this);
  33.       }
  34.    }
  35.    static function AddTween(tween)
  36.    {
  37.       tween.ID = mx.effects.Tween.ActiveTweens.length;
  38.       mx.effects.Tween.ActiveTweens.push(tween);
  39.       if(mx.effects.Tween.IntervalToken == undefined)
  40.       {
  41.          mx.effects.Tween.Dispatcher.DispatchTweens = mx.effects.Tween.DispatchTweens;
  42.          mx.effects.Tween.IntervalToken = setInterval(mx.effects.Tween.Dispatcher,"DispatchTweens",mx.effects.Tween.Interval);
  43.       }
  44.    }
  45.    static function RemoveTweenAt(index)
  46.    {
  47.       var _loc2_ = mx.effects.Tween.ActiveTweens;
  48.       if(index >= _loc2_.length || index < 0 || index == undefined)
  49.       {
  50.          return undefined;
  51.       }
  52.       _loc2_.splice(index,1);
  53.       var _loc4_ = _loc2_.length;
  54.       var _loc1_ = index;
  55.       while(_loc1_ < _loc4_)
  56.       {
  57.          _loc2_[_loc1_].ID--;
  58.          _loc1_ = _loc1_ + 1;
  59.       }
  60.       if(_loc4_ == 0)
  61.       {
  62.          clearInterval(mx.effects.Tween.IntervalToken);
  63.          delete mx.effects.Tween.IntervalToken;
  64.       }
  65.    }
  66.    static function DispatchTweens(Void)
  67.    {
  68.       var _loc2_ = mx.effects.Tween.ActiveTweens;
  69.       var _loc3_ = _loc2_.length;
  70.       var _loc1_ = 0;
  71.       while(_loc1_ < _loc3_)
  72.       {
  73.          _loc2_[_loc1_].doInterval();
  74.          _loc1_ = _loc1_ + 1;
  75.       }
  76.       updateAfterEvent();
  77.    }
  78.    function doInterval()
  79.    {
  80.       var _loc2_ = getTimer() - this.startTime;
  81.       var _loc3_ = this.getCurVal(_loc2_);
  82.       if(_loc2_ >= this.duration)
  83.       {
  84.          this.endTween();
  85.       }
  86.       else if(this.updateFunc != undefined)
  87.       {
  88.          this.listener[this.updateFunc](_loc3_);
  89.       }
  90.       else
  91.       {
  92.          this.listener.onTweenUpdate(_loc3_);
  93.       }
  94.    }
  95.    function getCurVal(curTime)
  96.    {
  97.       if(this.arrayMode)
  98.       {
  99.          var _loc3_ = new Array();
  100.          var _loc2_ = 0;
  101.          while(_loc2_ < this.initVal.length)
  102.          {
  103.             _loc3_[_loc2_] = this.easingEquation(curTime,this.initVal[_loc2_],this.endVal[_loc2_] - this.initVal[_loc2_],this.duration);
  104.             _loc2_ = _loc2_ + 1;
  105.          }
  106.          return _loc3_;
  107.       }
  108.       return this.easingEquation(curTime,this.initVal,this.endVal - this.initVal,this.duration);
  109.    }
  110.    function endTween()
  111.    {
  112.       if(this.endFunc != undefined)
  113.       {
  114.          this.listener[this.endFunc](this.endVal);
  115.       }
  116.       else
  117.       {
  118.          this.listener.onTweenEnd(this.endVal);
  119.       }
  120.       mx.effects.Tween.RemoveTweenAt(this.ID);
  121.    }
  122.    function setTweenHandlers(update, end)
  123.    {
  124.       this.updateFunc = update;
  125.       this.endFunc = end;
  126.    }
  127.    function easingEquation(t, b, c, d)
  128.    {
  129.       return c / 2 * (Math.sin(3.141592653589793 * (t / d - 0.5)) + 1) + b;
  130.    }
  131. }
  132.