home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2011 May / ME_2011_05.iso / Galileo-Video-Tutorial / system / player.swf / scripts / com / greensock / TweenLite.as < prev    next >
Encoding:
Text File  |  2010-11-30  |  16.7 KB  |  519 lines

  1. package com.greensock
  2. {
  3.    import com.greensock.core.*;
  4.    import flash.display.*;
  5.    import flash.events.*;
  6.    import flash.utils.*;
  7.    
  8.    public class TweenLite extends TweenCore
  9.    {
  10.       public static var onPluginEvent:Function;
  11.       
  12.       public static var overwriteManager:Object;
  13.       
  14.       public static var rootFrame:Number;
  15.       
  16.       public static var rootTimeline:SimpleTimeline;
  17.       
  18.       public static var rootFramesTimeline:SimpleTimeline;
  19.       
  20.       public static const version:Number = 11.36;
  21.       
  22.       public static var plugins:Object = {};
  23.       
  24.       public static var fastEaseLookup:Dictionary = new Dictionary(false);
  25.       
  26.       public static var killDelayedCallsTo:Function = TweenLite.killTweensOf;
  27.       
  28.       public static var defaultEase:Function = TweenLite.easeOut;
  29.       
  30.       public static var masterList:Dictionary = new Dictionary(false);
  31.       
  32.       private static var _shape:Shape = new Shape();
  33.       
  34.       protected static var _reservedProps:Object = {
  35.          "ease":1,
  36.          "delay":1,
  37.          "overwrite":1,
  38.          "onComplete":1,
  39.          "onCompleteParams":1,
  40.          "useFrames":1,
  41.          "runBackwards":1,
  42.          "startAt":1,
  43.          "onUpdate":1,
  44.          "onUpdateParams":1,
  45.          "roundProps":1,
  46.          "onStart":1,
  47.          "onStartParams":1,
  48.          "onInit":1,
  49.          "onInitParams":1,
  50.          "onReverseComplete":1,
  51.          "onReverseCompleteParams":1,
  52.          "onRepeat":1,
  53.          "onRepeatParams":1,
  54.          "proxiedEase":1,
  55.          "easeParams":1,
  56.          "yoyo":1,
  57.          "onCompleteListener":1,
  58.          "onUpdateListener":1,
  59.          "onStartListener":1,
  60.          "onReverseCompleteListener":1,
  61.          "onRepeatListener":1,
  62.          "orientToBezier":1,
  63.          "timeScale":1,
  64.          "immediateRender":1,
  65.          "repeat":1,
  66.          "repeatDelay":1,
  67.          "timeline":1,
  68.          "data":1,
  69.          "paused":1
  70.       };
  71.       
  72.       public var target:Object;
  73.       
  74.       public var propTweenLookup:Object;
  75.       
  76.       public var ratio:Number = 0;
  77.       
  78.       public var cachedPT1:PropTween;
  79.       
  80.       protected var _ease:Function;
  81.       
  82.       protected var _overwrite:uint;
  83.       
  84.       protected var _overwrittenProps:Object;
  85.       
  86.       protected var _hasPlugins:Boolean;
  87.       
  88.       protected var _notifyPluginsOfEnabled:Boolean;
  89.       
  90.       public function TweenLite(param1:Object, param2:Number, param3:Object)
  91.       {
  92.          var _loc5_:TweenLite = null;
  93.          super(param2,param3);
  94.          this.target = param1;
  95.          if(this.target is TweenCore && Boolean(this.vars.timeScale))
  96.          {
  97.             this.cachedTimeScale = 1;
  98.          }
  99.          this.propTweenLookup = {};
  100.          this._ease = defaultEase;
  101.          this._overwrite = Number(param3.overwrite) <= -1 || !overwriteManager.enabled && param3.overwrite > 1 ? uint(overwriteManager.mode) : uint(int(param3.overwrite));
  102.          var _loc4_:Array = masterList[param1];
  103.          if(!_loc4_)
  104.          {
  105.             masterList[param1] = [this];
  106.          }
  107.          else if(this._overwrite == 1)
  108.          {
  109.             for each(_loc5_ in _loc4_)
  110.             {
  111.                if(!_loc5_.gc)
  112.                {
  113.                   _loc5_.setEnabled(false,false);
  114.                }
  115.             }
  116.             masterList[param1] = [this];
  117.          }
  118.          else
  119.          {
  120.             _loc4_[_loc4_.length] = this;
  121.          }
  122.          if(this.active || Boolean(this.vars.immediateRender))
  123.          {
  124.             this.renderTime(0,false,true);
  125.          }
  126.       }
  127.       
  128.       public static function initClass() : void
  129.       {
  130.          rootFrame = 0;
  131.          rootTimeline = new SimpleTimeline(null);
  132.          rootFramesTimeline = new SimpleTimeline(null);
  133.          rootTimeline.cachedStartTime = getTimer() * 0.001;
  134.          rootFramesTimeline.cachedStartTime = rootFrame;
  135.          rootTimeline.autoRemoveChildren = true;
  136.          rootFramesTimeline.autoRemoveChildren = true;
  137.          _shape.addEventListener(Event.ENTER_FRAME,updateAll,false,0,true);
  138.          if(overwriteManager == null)
  139.          {
  140.             overwriteManager = {
  141.                "mode":1,
  142.                "enabled":false
  143.             };
  144.          }
  145.       }
  146.       
  147.       public static function to(param1:Object, param2:Number, param3:Object) : TweenLite
  148.       {
  149.          return new TweenLite(param1,param2,param3);
  150.       }
  151.       
  152.       public static function from(param1:Object, param2:Number, param3:Object) : TweenLite
  153.       {
  154.          param3.runBackwards = true;
  155.          if(!("immediateRender" in param3))
  156.          {
  157.             param3.immediateRender = true;
  158.          }
  159.          return new TweenLite(param1,param2,param3);
  160.       }
  161.       
  162.       public static function delayedCall(param1:Number, param2:Function, param3:Array = null, param4:Boolean = false) : TweenLite
  163.       {
  164.          return new TweenLite(param2,0,{
  165.             "delay":param1,
  166.             "onComplete":param2,
  167.             "onCompleteParams":param3,
  168.             "immediateRender":false,
  169.             "useFrames":param4,
  170.             "overwrite":0
  171.          });
  172.       }
  173.       
  174.       protected static function updateAll(param1:Event = null) : void
  175.       {
  176.          var _loc2_:Dictionary = null;
  177.          var _loc3_:Object = null;
  178.          var _loc4_:Array = null;
  179.          var _loc5_:int = 0;
  180.          rootTimeline.renderTime((getTimer() * 0.001 - rootTimeline.cachedStartTime) * rootTimeline.cachedTimeScale,false,false);
  181.          ++rootFrame;
  182.          rootFramesTimeline.renderTime((rootFrame - rootFramesTimeline.cachedStartTime) * rootFramesTimeline.cachedTimeScale,false,false);
  183.          if(!(rootFrame % 60))
  184.          {
  185.             _loc2_ = masterList;
  186.             for(_loc3_ in _loc2_)
  187.             {
  188.                _loc4_ = _loc2_[_loc3_];
  189.                _loc5_ = int(_loc4_.length);
  190.                while(--_loc5_ > -1)
  191.                {
  192.                   if(TweenLite(_loc4_[_loc5_]).gc)
  193.                   {
  194.                      _loc4_.splice(_loc5_,1);
  195.                   }
  196.                }
  197.                if(_loc4_.length == 0)
  198.                {
  199.                   delete _loc2_[_loc3_];
  200.                }
  201.             }
  202.          }
  203.       }
  204.       
  205.       public static function killTweensOf(param1:Object, param2:Boolean = false, param3:Object = null) : void
  206.       {
  207.          var _loc4_:Array = null;
  208.          var _loc5_:int = 0;
  209.          var _loc6_:TweenLite = null;
  210.          if(param1 in masterList)
  211.          {
  212.             _loc4_ = masterList[param1];
  213.             _loc5_ = int(_loc4_.length);
  214.             while(--_loc5_ > -1)
  215.             {
  216.                _loc6_ = _loc4_[_loc5_];
  217.                if(!_loc6_.gc)
  218.                {
  219.                   if(param2)
  220.                   {
  221.                      _loc6_.complete(false,false);
  222.                   }
  223.                   if(param3 != null)
  224.                   {
  225.                      _loc6_.killVars(param3);
  226.                   }
  227.                   if(param3 == null || _loc6_.cachedPT1 == null && _loc6_.initted)
  228.                   {
  229.                      _loc6_.setEnabled(false,false);
  230.                   }
  231.                }
  232.             }
  233.             if(param3 == null)
  234.             {
  235.                delete masterList[param1];
  236.             }
  237.          }
  238.       }
  239.       
  240.       protected static function easeOut(param1:Number, param2:Number, param3:Number, param4:Number) : Number
  241.       {
  242.          return 1 - (param1 = 1 - param1 / param4) * param1;
  243.       }
  244.       
  245.       protected function init() : void
  246.       {
  247.          var _loc1_:String = null;
  248.          var _loc2_:int = 0;
  249.          var _loc3_:* = undefined;
  250.          var _loc4_:Boolean = false;
  251.          var _loc5_:Array = null;
  252.          var _loc6_:PropTween = null;
  253.          if(this.vars.onInit)
  254.          {
  255.             this.vars.onInit.apply(null,this.vars.onInitParams);
  256.          }
  257.          if(typeof this.vars.ease == "function")
  258.          {
  259.             this._ease = this.vars.ease;
  260.          }
  261.          if(this.vars.easeParams)
  262.          {
  263.             this.vars.proxiedEase = this._ease;
  264.             this._ease = this.easeProxy;
  265.          }
  266.          this.cachedPT1 = null;
  267.          this.propTweenLookup = {};
  268.          for(_loc1_ in this.vars)
  269.          {
  270.             if(!(_loc1_ in _reservedProps && !(_loc1_ == "timeScale" && this.target is TweenCore)))
  271.             {
  272.                if(_loc1_ in plugins && Boolean((_loc3_ = new (plugins[_loc1_] as Class)()).onInitTween(this.target,this.vars[_loc1_],this)))
  273.                {
  274.                   this.cachedPT1 = new PropTween(_loc3_,"changeFactor",0,1,_loc3_.overwriteProps.length == 1 ? _loc3_.overwriteProps[0] : "_MULTIPLE_",true,this.cachedPT1);
  275.                   if(this.cachedPT1.name == "_MULTIPLE_")
  276.                   {
  277.                      _loc2_ = int(_loc3_.overwriteProps.length);
  278.                      while(--_loc2_ > -1)
  279.                      {
  280.                         this.propTweenLookup[_loc3_.overwriteProps[_loc2_]] = this.cachedPT1;
  281.                      }
  282.                   }
  283.                   else
  284.                   {
  285.                      this.propTweenLookup[this.cachedPT1.name] = this.cachedPT1;
  286.                   }
  287.                   if(_loc3_.priority)
  288.                   {
  289.                      this.cachedPT1.priority = _loc3_.priority;
  290.                      _loc4_ = true;
  291.                   }
  292.                   if(Boolean(_loc3_.onDisable) || Boolean(_loc3_.onEnable))
  293.                   {
  294.                      this._notifyPluginsOfEnabled = true;
  295.                   }
  296.                   this._hasPlugins = true;
  297.                }
  298.                else
  299.                {
  300.                   this.cachedPT1 = new PropTween(this.target,_loc1_,Number(this.target[_loc1_]),typeof this.vars[_loc1_] == "number" ? Number(this.vars[_loc1_]) - this.target[_loc1_] : Number(this.vars[_loc1_]),_loc1_,false,this.cachedPT1);
  301.                   this.propTweenLookup[_loc1_] = this.cachedPT1;
  302.                }
  303.             }
  304.          }
  305.          if(_loc4_)
  306.          {
  307.             onPluginEvent("onInit",this);
  308.          }
  309.          if(this.vars.runBackwards)
  310.          {
  311.             _loc6_ = this.cachedPT1;
  312.             while(_loc6_)
  313.             {
  314.                _loc6_.start += _loc6_.change;
  315.                _loc6_.change = -_loc6_.change;
  316.                _loc6_ = _loc6_.nextNode;
  317.             }
  318.          }
  319.          _hasUpdate = Boolean(this.vars.onUpdate != null);
  320.          if(this._overwrittenProps)
  321.          {
  322.             this.killVars(this._overwrittenProps);
  323.             if(this.cachedPT1 == null)
  324.             {
  325.                this.setEnabled(false,false);
  326.             }
  327.          }
  328.          if(this._overwrite > 1 && this.cachedPT1 && (_loc5_ = masterList[this.target]) && _loc5_.length > 1)
  329.          {
  330.             if(overwriteManager.manageOverwrites(this,this.propTweenLookup,_loc5_,this._overwrite))
  331.             {
  332.                this.init();
  333.             }
  334.          }
  335.          this.initted = true;
  336.       }
  337.       
  338.       override public function renderTime(param1:Number, param2:Boolean = false, param3:Boolean = false) : void
  339.       {
  340.          var _loc4_:Boolean = false;
  341.          var _loc5_:Number = this.cachedTime;
  342.          if(param1 >= this.cachedDuration)
  343.          {
  344.             this.cachedTotalTime = this.cachedTime = this.cachedDuration;
  345.             this.ratio = 1;
  346.             _loc4_ = true;
  347.             if(this.cachedDuration == 0)
  348.             {
  349.                if((param1 == 0 || _rawPrevTime < 0) && _rawPrevTime != param1)
  350.                {
  351.                   param3 = true;
  352.                }
  353.                _rawPrevTime = param1;
  354.             }
  355.          }
  356.          else if(param1 <= 0)
  357.          {
  358.             this.cachedTotalTime = this.cachedTime = this.ratio = 0;
  359.             if(param1 < 0)
  360.             {
  361.                this.active = false;
  362.                if(this.cachedDuration == 0)
  363.                {
  364.                   if(_rawPrevTime > 0)
  365.                   {
  366.                      param3 = true;
  367.                      _loc4_ = true;
  368.                   }
  369.                   _rawPrevTime = param1;
  370.                }
  371.             }
  372.             if(this.cachedReversed && _loc5_ != 0)
  373.             {
  374.                _loc4_ = true;
  375.             }
  376.          }
  377.          else
  378.          {
  379.             this.cachedTotalTime = this.cachedTime = param1;
  380.             this.ratio = this._ease(param1,0,1,this.cachedDuration);
  381.          }
  382.          if(this.cachedTime == _loc5_ && !param3)
  383.          {
  384.             return;
  385.          }
  386.          if(!this.initted)
  387.          {
  388.             this.init();
  389.             if(!_loc4_ && Boolean(this.cachedTime))
  390.             {
  391.                this.ratio = this._ease(this.cachedTime,0,1,this.cachedDuration);
  392.             }
  393.          }
  394.          if(!this.active && !this.cachedPaused)
  395.          {
  396.             this.active = true;
  397.          }
  398.          if(_loc5_ == 0 && this.vars.onStart && this.cachedTime != 0 && !param2)
  399.          {
  400.             this.vars.onStart.apply(null,this.vars.onStartParams);
  401.          }
  402.          var _loc6_:PropTween = this.cachedPT1;
  403.          while(_loc6_)
  404.          {
  405.             _loc6_.target[_loc6_.property] = _loc6_.start + this.ratio * _loc6_.change;
  406.             _loc6_ = _loc6_.nextNode;
  407.          }
  408.          if(_hasUpdate && !param2)
  409.          {
  410.             this.vars.onUpdate.apply(null,this.vars.onUpdateParams);
  411.          }
  412.          if(_loc4_)
  413.          {
  414.             if(this._hasPlugins && Boolean(this.cachedPT1))
  415.             {
  416.                onPluginEvent("onComplete",this);
  417.             }
  418.             complete(true,param2);
  419.          }
  420.       }
  421.       
  422.       public function killVars(param1:Object, param2:Boolean = true) : Boolean
  423.       {
  424.          var _loc3_:String = null;
  425.          var _loc4_:PropTween = null;
  426.          var _loc5_:Boolean = false;
  427.          if(this._overwrittenProps == null)
  428.          {
  429.             this._overwrittenProps = {};
  430.          }
  431.          for(_loc3_ in param1)
  432.          {
  433.             if(_loc3_ in this.propTweenLookup)
  434.             {
  435.                _loc4_ = this.propTweenLookup[_loc3_];
  436.                if(_loc4_.isPlugin && _loc4_.name == "_MULTIPLE_")
  437.                {
  438.                   _loc4_.target.killProps(param1);
  439.                   if(_loc4_.target.overwriteProps.length == 0)
  440.                   {
  441.                      _loc4_.name = "";
  442.                   }
  443.                }
  444.                if(_loc4_.name != "_MULTIPLE_")
  445.                {
  446.                   if(_loc4_.nextNode)
  447.                   {
  448.                      _loc4_.nextNode.prevNode = _loc4_.prevNode;
  449.                   }
  450.                   if(_loc4_.prevNode)
  451.                   {
  452.                      _loc4_.prevNode.nextNode = _loc4_.nextNode;
  453.                   }
  454.                   else if(this.cachedPT1 == _loc4_)
  455.                   {
  456.                      this.cachedPT1 = _loc4_.nextNode;
  457.                   }
  458.                   if(_loc4_.isPlugin && Boolean(_loc4_.target.onDisable))
  459.                   {
  460.                      _loc4_.target.onDisable();
  461.                      if(_loc4_.target.activeDisable)
  462.                      {
  463.                         _loc5_ = true;
  464.                      }
  465.                   }
  466.                   delete this.propTweenLookup[_loc3_];
  467.                }
  468.             }
  469.             if(param2 && param1 != this._overwrittenProps)
  470.             {
  471.                this._overwrittenProps[_loc3_] = 1;
  472.             }
  473.          }
  474.          return _loc5_;
  475.       }
  476.       
  477.       override public function invalidate() : void
  478.       {
  479.          if(this._notifyPluginsOfEnabled && Boolean(this.cachedPT1))
  480.          {
  481.             onPluginEvent("onDisable",this);
  482.          }
  483.          this.cachedPT1 = null;
  484.          this._overwrittenProps = null;
  485.          _hasUpdate = this.initted = this.active = this._notifyPluginsOfEnabled = false;
  486.          this.propTweenLookup = {};
  487.       }
  488.       
  489.       override public function setEnabled(param1:Boolean, param2:Boolean = false) : Boolean
  490.       {
  491.          var _loc3_:Array = null;
  492.          if(param1)
  493.          {
  494.             _loc3_ = TweenLite.masterList[this.target];
  495.             if(!_loc3_)
  496.             {
  497.                TweenLite.masterList[this.target] = [this];
  498.             }
  499.             else
  500.             {
  501.                _loc3_[_loc3_.length] = this;
  502.             }
  503.          }
  504.          super.setEnabled(param1,param2);
  505.          if(this._notifyPluginsOfEnabled && Boolean(this.cachedPT1))
  506.          {
  507.             return onPluginEvent(param1 ? "onEnable" : "onDisable",this);
  508.          }
  509.          return false;
  510.       }
  511.       
  512.       protected function easeProxy(param1:Number, param2:Number, param3:Number, param4:Number) : Number
  513.       {
  514.          return this.vars.proxiedEase.apply(null,arguments.concat(this.vars.easeParams));
  515.       }
  516.    }
  517. }
  518.  
  519.