home *** CD-ROM | disk | FTP | other *** search
/ Ice Age Fan CD 1 / CD1_Scrat.iso / flash / data / game.swf / scripts / gs / TweenLite.as < prev    next >
Encoding:
Text File  |  2012-07-04  |  16.5 KB  |  512 lines

  1. package gs
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.Sprite;
  5.    import flash.events.Event;
  6.    import flash.events.TimerEvent;
  7.    import flash.geom.ColorTransform;
  8.    import flash.media.SoundChannel;
  9.    import flash.utils.*;
  10.    
  11.    public class TweenLite
  12.    {
  13.       protected static var _curTime:uint;
  14.       
  15.       private static var _classInitted:Boolean;
  16.       
  17.       private static var _listening:Boolean;
  18.       
  19.       public static var version:Number = 7.01;
  20.       
  21.       public static var killDelayedCallsTo:Function = TweenLite.killTweensOf;
  22.       
  23.       public static var defaultEase:Function = TweenLite.easeOut;
  24.       
  25.       protected static var _all:Dictionary = new Dictionary();
  26.       
  27.       private static var _sprite:Sprite = new Sprite();
  28.       
  29.       private static var _timer:Timer = new Timer(2000);
  30.       
  31.       public var duration:Number;
  32.       
  33.       public var vars:Object;
  34.       
  35.       public var delay:Number;
  36.       
  37.       public var startTime:int;
  38.       
  39.       public var initTime:int;
  40.       
  41.       public var tweens:Array;
  42.       
  43.       public var target:Object;
  44.       
  45.       protected var _active:Boolean;
  46.       
  47.       protected var _subTweens:Array;
  48.       
  49.       protected var _hst:Boolean;
  50.       
  51.       protected var _isDisplayObject:Boolean;
  52.       
  53.       protected var _initted:Boolean;
  54.       
  55.       public function TweenLite(param1:Object, param2:Number, param3:Object)
  56.       {
  57.          var _loc4_:* = undefined;
  58.          super();
  59.          if(param1 == null)
  60.          {
  61.             return;
  62.          }
  63.          if(param3.overwrite != false && param1 != null || _all[param1] == undefined)
  64.          {
  65.             delete _all[param1];
  66.             _all[param1] = new Dictionary();
  67.          }
  68.          _all[param1][this] = this;
  69.          this.vars = param3;
  70.          this.duration = param2 || 0.001;
  71.          this.delay = Number(param3.delay) || 0;
  72.          _active = param2 == 0 && this.delay == 0;
  73.          this.target = param1;
  74.          _isDisplayObject = param1 is DisplayObject;
  75.          if(!(this.vars.ease is Function))
  76.          {
  77.             this.vars.ease = defaultEase;
  78.          }
  79.          if(this.vars.easeParams != null)
  80.          {
  81.             this.vars.proxiedEase = this.vars.ease;
  82.             this.vars.ease = easeProxy;
  83.          }
  84.          if(!isNaN(Number(this.vars.autoAlpha)))
  85.          {
  86.             this.vars.alpha = Number(this.vars.autoAlpha);
  87.             this.vars.visible = this.vars.alpha > 0;
  88.          }
  89.          this.tweens = [];
  90.          _subTweens = [];
  91.          _hst = _initted = false;
  92.          if(!_classInitted)
  93.          {
  94.             _curTime = getTimer();
  95.             _sprite.addEventListener(Event.ENTER_FRAME,executeAll);
  96.             _classInitted = true;
  97.          }
  98.          this.initTime = _curTime;
  99.          if(this.vars.runBackwards == true && this.vars.renderOnStart != true || _active)
  100.          {
  101.             initTweenVals();
  102.             this.startTime = _curTime;
  103.             if(_active)
  104.             {
  105.                render(this.startTime + 1);
  106.             }
  107.             else
  108.             {
  109.                render(this.startTime);
  110.             }
  111.             _loc4_ = this.vars.visible;
  112.             if(this.vars.isTV == true)
  113.             {
  114.                _loc4_ = this.vars.exposedProps.visible;
  115.             }
  116.             if(_loc4_ != null && this.vars.runBackwards == true && _isDisplayObject)
  117.             {
  118.                this.target.visible = Boolean(_loc4_);
  119.             }
  120.          }
  121.          if(!_listening && !_active)
  122.          {
  123.             _timer.addEventListener("timer",killGarbage);
  124.             _timer.start();
  125.             _listening = true;
  126.          }
  127.       }
  128.       
  129.       public static function to(param1:Object, param2:Number, param3:Object) : TweenLite
  130.       {
  131.          return new TweenLite(param1,param2,param3);
  132.       }
  133.       
  134.       public static function from(param1:Object, param2:Number, param3:Object) : TweenLite
  135.       {
  136.          param3.runBackwards = true;
  137.          return new TweenLite(param1,param2,param3);
  138.       }
  139.       
  140.       public static function delayedCall(param1:Number, param2:Function, param3:Array = null) : TweenLite
  141.       {
  142.          return new TweenLite(param2,0,{
  143.             "delay":param1,
  144.             "onComplete":param2,
  145.             "onCompleteParams":param3,
  146.             "overwrite":false
  147.          });
  148.       }
  149.       
  150.       public static function executeAll(param1:Event = null) : void
  151.       {
  152.          var _loc3_:Dictionary = null;
  153.          var _loc4_:Object = null;
  154.          var _loc5_:Object = null;
  155.          var _loc2_:uint = uint(_curTime = getTimer());
  156.          if(_listening)
  157.          {
  158.             _loc3_ = _all;
  159.             for each(_loc4_ in _loc3_)
  160.             {
  161.                for(_loc5_ in _loc4_)
  162.                {
  163.                   if(_loc4_[_loc5_] != undefined && Boolean(_loc4_[_loc5_].active))
  164.                   {
  165.                      _loc4_[_loc5_].render(_loc2_);
  166.                   }
  167.                }
  168.             }
  169.          }
  170.       }
  171.       
  172.       public static function removeTween(param1:TweenLite = null) : void
  173.       {
  174.          if(param1 != null && _all[param1.target] != undefined)
  175.          {
  176.             delete _all[param1.target][param1];
  177.          }
  178.       }
  179.       
  180.       public static function killTweensOf(param1:Object = null, param2:Boolean = false) : void
  181.       {
  182.          var _loc3_:Object = null;
  183.          var _loc4_:* = undefined;
  184.          if(param1 != null && _all[param1] != undefined)
  185.          {
  186.             if(param2)
  187.             {
  188.                _loc3_ = _all[param1];
  189.                for(_loc4_ in _loc3_)
  190.                {
  191.                   _loc3_[_loc4_].complete(false);
  192.                }
  193.             }
  194.             delete _all[param1];
  195.          }
  196.       }
  197.       
  198.       public static function killGarbage(param1:TimerEvent) : void
  199.       {
  200.          var _loc3_:Boolean = false;
  201.          var _loc4_:Object = null;
  202.          var _loc5_:Object = null;
  203.          var _loc6_:Object = null;
  204.          var _loc2_:uint = 0;
  205.          for(_loc4_ in _all)
  206.          {
  207.             _loc3_ = false;
  208.             var _loc9_:int = 0;
  209.             var _loc10_:* = _all[_loc4_];
  210.             for(_loc5_ in _loc10_)
  211.             {
  212.                _loc3_ = true;
  213.             }
  214.             if(!_loc3_)
  215.             {
  216.                delete _all[_loc4_];
  217.             }
  218.             else
  219.             {
  220.                _loc2_++;
  221.             }
  222.          }
  223.          if(_loc2_ == 0)
  224.          {
  225.             _timer.removeEventListener("timer",killGarbage);
  226.             _timer.stop();
  227.             _listening = false;
  228.          }
  229.       }
  230.       
  231.       public static function easeOut(param1:Number, param2:Number, param3:Number, param4:Number) : Number
  232.       {
  233.          return -param3 * (param1 = param1 / param4) * (param1 - 2) + param2;
  234.       }
  235.       
  236.       public static function tintProxy(param1:Object) : void
  237.       {
  238.          var _loc2_:Number = Number(param1.target.progress);
  239.          var _loc3_:Number = 1 - _loc2_;
  240.          var _loc4_:Object = param1.info.color;
  241.          var _loc5_:Object = param1.info.endColor;
  242.          param1.info.target.transform.colorTransform = new ColorTransform(_loc4_.redMultiplier * _loc3_ + _loc5_.redMultiplier * _loc2_,_loc4_.greenMultiplier * _loc3_ + _loc5_.greenMultiplier * _loc2_,_loc4_.blueMultiplier * _loc3_ + _loc5_.blueMultiplier * _loc2_,_loc4_.alphaMultiplier * _loc3_ + _loc5_.alphaMultiplier * _loc2_,_loc4_.redOffset * _loc3_ + _loc5_.redOffset * _loc2_,_loc4_.greenOffset * _loc3_ + _loc5_.greenOffset * _loc2_,_loc4_.blueOffset * _loc3_ + _loc5_.blueOffset * _loc2_,_loc4_.alphaOffset * _loc3_ + _loc5_.alphaOffset * _loc2_);
  243.       }
  244.       
  245.       public static function frameProxy(param1:Object) : void
  246.       {
  247.          param1.info.target.gotoAndStop(Math.round(param1.target.frame));
  248.       }
  249.       
  250.       public static function volumeProxy(param1:Object) : void
  251.       {
  252.          param1.info.target.soundTransform = param1.target;
  253.       }
  254.       
  255.       public function initTweenVals(param1:Boolean = false, param2:String = "") : void
  256.       {
  257.          var _loc3_:String = null;
  258.          var _loc4_:int = 0;
  259.          var _loc6_:Array = null;
  260.          var _loc7_:ColorTransform = null;
  261.          var _loc8_:ColorTransform = null;
  262.          var _loc9_:Object = null;
  263.          var _loc5_:Object = this.vars;
  264.          if(_loc5_.isTV == true)
  265.          {
  266.             _loc5_ = _loc5_.exposedProps;
  267.          }
  268.          if(this.target is Array)
  269.          {
  270.             _loc6_ = this.vars.endArray || [];
  271.             _loc4_ = 0;
  272.             while(_loc4_ < _loc6_.length)
  273.             {
  274.                if(this.target[_loc4_] != _loc6_[_loc4_] && this.target[_loc4_] != undefined)
  275.                {
  276.                   this.tweens.push({
  277.                      "o":this.target,
  278.                      "p":_loc4_.toString(),
  279.                      "s":this.target[_loc4_],
  280.                      "c":_loc6_[_loc4_] - this.target[_loc4_]
  281.                   });
  282.                }
  283.                _loc4_++;
  284.             }
  285.          }
  286.          else
  287.          {
  288.             if((typeof _loc5_.tint != "undefined" || this.vars.removeTint == true) && _isDisplayObject)
  289.             {
  290.                _loc7_ = this.target.transform.colorTransform;
  291.                _loc8_ = new ColorTransform();
  292.                if(_loc5_.alpha != undefined)
  293.                {
  294.                   _loc8_.alphaMultiplier = _loc5_.alpha;
  295.                   delete _loc5_.alpha;
  296.                }
  297.                else
  298.                {
  299.                   _loc8_.alphaMultiplier = this.target.alpha;
  300.                }
  301.                if(this.vars.removeTint != true && (_loc5_.tint != null && _loc5_.tint != "" || _loc5_.tint == 0))
  302.                {
  303.                   _loc8_.color = _loc5_.tint;
  304.                }
  305.                addSubTween(tintProxy,{"progress":0},{"progress":1},{
  306.                   "target":this.target,
  307.                   "color":_loc7_,
  308.                   "endColor":_loc8_
  309.                });
  310.             }
  311.             if(_loc5_.frame != null && _isDisplayObject)
  312.             {
  313.                addSubTween(frameProxy,{"frame":this.target.currentFrame},{"frame":_loc5_.frame},{"target":this.target});
  314.             }
  315.             if(!isNaN(this.vars.volume) && (_isDisplayObject || this.target is SoundChannel))
  316.             {
  317.                addSubTween(volumeProxy,this.target.soundTransform,{"volume":this.vars.volume},{"target":this.target});
  318.             }
  319.             for(_loc3_ in _loc5_)
  320.             {
  321.                if(!(_loc3_ == "ease" || _loc3_ == "delay" || _loc3_ == "overwrite" || _loc3_ == "onComplete" || _loc3_ == "onCompleteParams" || _loc3_ == "runBackwards" || _loc3_ == "persist" || _loc3_ == "onUpdate" || _loc3_ == "onUpdateParams" || _loc3_ == "volume" || _loc3_ == "onStart" || _loc3_ == "onStartParams" || _loc3_ == "renderOnStart" || _loc3_ == "proxiedEase" || _loc3_ == "easeParams" || param1 && param2.indexOf(" " + _loc3_ + " ") != -1))
  322.                {
  323.                   if(!(_isDisplayObject && (_loc3_ == "visible" || _loc3_ == "autoAlpha" || _loc3_ == "tint" || _loc3_ == "removeTint" || _loc3_ == "frame")))
  324.                   {
  325.                      if(typeof _loc5_[_loc3_] == "number")
  326.                      {
  327.                         this.tweens.push({
  328.                            "o":this.target,
  329.                            "p":_loc3_,
  330.                            "s":this.target[_loc3_],
  331.                            "c":_loc5_[_loc3_] - this.target[_loc3_]
  332.                         });
  333.                      }
  334.                      else
  335.                      {
  336.                         this.tweens.push({
  337.                            "o":this.target,
  338.                            "p":_loc3_,
  339.                            "s":this.target[_loc3_],
  340.                            "c":Number(_loc5_[_loc3_])
  341.                         });
  342.                      }
  343.                   }
  344.                }
  345.             }
  346.          }
  347.          if(this.vars.runBackwards == true)
  348.          {
  349.             _loc4_ = int(this.tweens.length - 1);
  350.             while(_loc4_ > -1)
  351.             {
  352.                _loc9_ = this.tweens[_loc4_];
  353.                _loc9_.s += _loc9_.c;
  354.                _loc9_.c *= -1;
  355.                _loc4_--;
  356.             }
  357.          }
  358.          if(_loc5_.visible == true && _isDisplayObject)
  359.          {
  360.             this.target.visible = true;
  361.          }
  362.          _initted = true;
  363.       }
  364.       
  365.       protected function addSubTween(param1:Function, param2:Object, param3:Object, param4:Object = null) : void
  366.       {
  367.          var _loc6_:String = null;
  368.          var _loc5_:Object = {
  369.             "proxy":param1,
  370.             "target":param2,
  371.             "info":param4
  372.          };
  373.          _subTweens.push(_loc5_);
  374.          for(_loc6_ in param3)
  375.          {
  376.             if(typeof param3[_loc6_] == "number")
  377.             {
  378.                this.tweens.push({
  379.                   "o":param2,
  380.                   "p":_loc6_,
  381.                   "s":param2[_loc6_],
  382.                   "c":param3[_loc6_] - param2[_loc6_],
  383.                   "sub":_loc5_
  384.                });
  385.             }
  386.             else
  387.             {
  388.                this.tweens.push({
  389.                   "o":param2,
  390.                   "p":_loc6_,
  391.                   "s":param2[_loc6_],
  392.                   "c":Number(param3[_loc6_]),
  393.                   "sub":_loc5_
  394.                });
  395.             }
  396.          }
  397.          _hst = true;
  398.       }
  399.       
  400.       public function render(param1:uint) : void
  401.       {
  402.          var _loc3_:Number = NaN;
  403.          var _loc4_:Object = null;
  404.          var _loc5_:int = 0;
  405.          var _loc2_:Number = (param1 - this.startTime) / 1000;
  406.          if(_loc2_ >= this.duration)
  407.          {
  408.             _loc2_ = this.duration;
  409.             _loc3_ = 1;
  410.          }
  411.          else
  412.          {
  413.             _loc3_ = Number(this.vars.ease(_loc2_,0,1,this.duration));
  414.          }
  415.          _loc5_ = int(this.tweens.length - 1);
  416.          while(_loc5_ > -1)
  417.          {
  418.             _loc4_ = this.tweens[_loc5_];
  419.             _loc4_.o[_loc4_.p] = _loc4_.s + _loc3_ * _loc4_.c;
  420.             _loc5_--;
  421.          }
  422.          if(_hst)
  423.          {
  424.             _loc5_ = int(_subTweens.length - 1);
  425.             while(_loc5_ > -1)
  426.             {
  427.                _subTweens[_loc5_].proxy(_subTweens[_loc5_]);
  428.                _loc5_--;
  429.             }
  430.          }
  431.          if(this.vars.onUpdate != null)
  432.          {
  433.             this.vars.onUpdate.apply(null,this.vars.onUpdateParams);
  434.          }
  435.          if(_loc2_ == this.duration)
  436.          {
  437.             complete(true);
  438.          }
  439.       }
  440.       
  441.       public function complete(param1:Boolean = false) : void
  442.       {
  443.          if(!param1)
  444.          {
  445.             if(!_initted)
  446.             {
  447.                initTweenVals();
  448.             }
  449.             this.startTime = _curTime - this.duration * 1000;
  450.             render(_curTime);
  451.             return;
  452.          }
  453.          if(this.vars.visible != undefined && _isDisplayObject)
  454.          {
  455.             if(!isNaN(this.vars.autoAlpha) && this.target.alpha == 0)
  456.             {
  457.                this.target.visible = false;
  458.             }
  459.             else if(this.vars.runBackwards != true)
  460.             {
  461.                this.target.visible = this.vars.visible;
  462.             }
  463.          }
  464.          if(this.vars.persist != true)
  465.          {
  466.             removeTween(this);
  467.          }
  468.          if(this.vars.onComplete != null)
  469.          {
  470.             this.vars.onComplete.apply(null,this.vars.onCompleteParams);
  471.          }
  472.       }
  473.       
  474.       protected function easeProxy(param1:Number, param2:Number, param3:Number, param4:Number) : Number
  475.       {
  476.          return this.vars.proxiedEase.apply(null,arguments.concat(this.vars.easeParams));
  477.       }
  478.       
  479.       public function get active() : Boolean
  480.       {
  481.          if(_active)
  482.          {
  483.             return true;
  484.          }
  485.          if((_curTime - this.initTime) / 1000 > this.delay)
  486.          {
  487.             _active = true;
  488.             this.startTime = this.initTime + this.delay * 1000;
  489.             if(!_initted)
  490.             {
  491.                initTweenVals();
  492.             }
  493.             else if(this.vars.visible != undefined && _isDisplayObject)
  494.             {
  495.                this.target.visible = true;
  496.             }
  497.             if(this.vars.onStart != null)
  498.             {
  499.                this.vars.onStart.apply(null,this.vars.onStartParams);
  500.             }
  501.             if(this.duration == 0.001)
  502.             {
  503.                --this.startTime;
  504.             }
  505.             return true;
  506.          }
  507.          return false;
  508.       }
  509.    }
  510. }
  511.  
  512.