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