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

  1. package com.greensock.plugins
  2. {
  3.    import com.greensock.*;
  4.    
  5.    public class BezierPlugin extends TweenPlugin
  6.    {
  7.       public static const API:Number = 1;
  8.       
  9.       protected static const _RAD2DEG:Number = 180 / Math.PI;
  10.       
  11.       protected var _target:Object;
  12.       
  13.       protected var _orientData:Array;
  14.       
  15.       protected var _orient:Boolean;
  16.       
  17.       protected var _future:Object = {};
  18.       
  19.       protected var _beziers:Object;
  20.       
  21.       public function BezierPlugin()
  22.       {
  23.          super();
  24.          this.propName = "bezier";
  25.          this.overwriteProps = [];
  26.       }
  27.       
  28.       public static function parseBeziers(param1:Object, param2:Boolean = false) : Object
  29.       {
  30.          var _loc3_:int = 0;
  31.          var _loc4_:Array = null;
  32.          var _loc5_:Object = null;
  33.          var _loc6_:String = null;
  34.          var _loc7_:Object = {};
  35.          if(param2)
  36.          {
  37.             for(_loc6_ in param1)
  38.             {
  39.                _loc4_ = param1[_loc6_];
  40.                _loc7_[_loc6_] = _loc5_ = [];
  41.                if(_loc4_.length > 2)
  42.                {
  43.                   _loc5_[_loc5_.length] = [_loc4_[0],_loc4_[1] - (_loc4_[2] - _loc4_[0]) / 4,_loc4_[1]];
  44.                   _loc3_ = 1;
  45.                   while(_loc3_ < _loc4_.length - 1)
  46.                   {
  47.                      _loc5_[_loc5_.length] = [_loc4_[_loc3_],_loc4_[_loc3_] + (_loc4_[_loc3_] - _loc5_[_loc3_ - 1][1]),_loc4_[_loc3_ + 1]];
  48.                      _loc3_++;
  49.                   }
  50.                }
  51.                else
  52.                {
  53.                   _loc5_[_loc5_.length] = [_loc4_[0],(_loc4_[0] + _loc4_[1]) / 2,_loc4_[1]];
  54.                }
  55.             }
  56.          }
  57.          else
  58.          {
  59.             for(_loc6_ in param1)
  60.             {
  61.                _loc4_ = param1[_loc6_];
  62.                _loc7_[_loc6_] = _loc5_ = [];
  63.                if(_loc4_.length > 3)
  64.                {
  65.                   _loc5_[_loc5_.length] = [_loc4_[0],_loc4_[1],(_loc4_[1] + _loc4_[2]) / 2];
  66.                   _loc3_ = 2;
  67.                   while(_loc3_ < _loc4_.length - 2)
  68.                   {
  69.                      _loc5_[_loc5_.length] = [_loc5_[_loc3_ - 2][2],_loc4_[_loc3_],(_loc4_[_loc3_] + _loc4_[_loc3_ + 1]) / 2];
  70.                      _loc3_++;
  71.                   }
  72.                   _loc5_[_loc5_.length] = [_loc5_[_loc5_.length - 1][2],_loc4_[_loc4_.length - 2],_loc4_[_loc4_.length - 1]];
  73.                }
  74.                else if(_loc4_.length == 3)
  75.                {
  76.                   _loc5_[_loc5_.length] = [_loc4_[0],_loc4_[1],_loc4_[2]];
  77.                }
  78.                else if(_loc4_.length == 2)
  79.                {
  80.                   _loc5_[_loc5_.length] = [_loc4_[0],(_loc4_[0] + _loc4_[1]) / 2,_loc4_[1]];
  81.                }
  82.             }
  83.          }
  84.          return _loc7_;
  85.       }
  86.       
  87.       override public function onInitTween(param1:Object, param2:*, param3:TweenLite) : Boolean
  88.       {
  89.          if(!(param2 is Array))
  90.          {
  91.             return false;
  92.          }
  93.          this.init(param3,param2 as Array,false);
  94.          return true;
  95.       }
  96.       
  97.       protected function init(param1:TweenLite, param2:Array, param3:Boolean) : void
  98.       {
  99.          var _loc6_:int = 0;
  100.          var _loc7_:String = null;
  101.          var _loc8_:Object = null;
  102.          this._target = param1.target;
  103.          var _loc4_:Object = param1.vars.isTV == true ? param1.vars.exposedVars : param1.vars;
  104.          if(_loc4_.orientToBezier == true)
  105.          {
  106.             this._orientData = [["x","y","rotation",0,0.01]];
  107.             this._orient = true;
  108.          }
  109.          else if(_loc4_.orientToBezier is Array)
  110.          {
  111.             this._orientData = _loc4_.orientToBezier;
  112.             this._orient = true;
  113.          }
  114.          var _loc5_:Object = {};
  115.          _loc6_ = 0;
  116.          while(_loc6_ < param2.length)
  117.          {
  118.             for(_loc7_ in param2[_loc6_])
  119.             {
  120.                if(_loc5_[_loc7_] == undefined)
  121.                {
  122.                   _loc5_[_loc7_] = [param1.target[_loc7_]];
  123.                }
  124.                if(typeof param2[_loc6_][_loc7_] == "number")
  125.                {
  126.                   _loc5_[_loc7_].push(param2[_loc6_][_loc7_]);
  127.                }
  128.                else
  129.                {
  130.                   _loc5_[_loc7_].push(param1.target[_loc7_] + Number(param2[_loc6_][_loc7_]));
  131.                }
  132.             }
  133.             _loc6_++;
  134.          }
  135.          for(_loc7_ in _loc5_)
  136.          {
  137.             this.overwriteProps[this.overwriteProps.length] = _loc7_;
  138.             if(_loc4_[_loc7_] != undefined)
  139.             {
  140.                if(typeof _loc4_[_loc7_] == "number")
  141.                {
  142.                   _loc5_[_loc7_].push(_loc4_[_loc7_]);
  143.                }
  144.                else
  145.                {
  146.                   _loc5_[_loc7_].push(param1.target[_loc7_] + Number(_loc4_[_loc7_]));
  147.                }
  148.                _loc8_ = {};
  149.                _loc8_[_loc7_] = true;
  150.                param1.killVars(_loc8_,false);
  151.                delete _loc4_[_loc7_];
  152.             }
  153.          }
  154.          this._beziers = parseBeziers(_loc5_,param3);
  155.       }
  156.       
  157.       override public function killProps(param1:Object) : void
  158.       {
  159.          var _loc2_:String = null;
  160.          for(_loc2_ in this._beziers)
  161.          {
  162.             if(_loc2_ in param1)
  163.             {
  164.                delete this._beziers[_loc2_];
  165.             }
  166.          }
  167.          super.killProps(param1);
  168.       }
  169.       
  170.       override public function set changeFactor(param1:Number) : void
  171.       {
  172.          var _loc2_:int = 0;
  173.          var _loc3_:String = null;
  174.          var _loc4_:Object = null;
  175.          var _loc5_:Number = NaN;
  176.          var _loc6_:uint = 0;
  177.          var _loc7_:Number = NaN;
  178.          var _loc8_:Object = null;
  179.          var _loc9_:Number = NaN;
  180.          var _loc10_:Number = NaN;
  181.          var _loc11_:Array = null;
  182.          var _loc12_:Number = NaN;
  183.          var _loc13_:Object = null;
  184.          var _loc14_:Boolean = false;
  185.          if(param1 == 1)
  186.          {
  187.             for(_loc3_ in this._beziers)
  188.             {
  189.                _loc2_ = this._beziers[_loc3_].length - 1;
  190.                this._target[_loc3_] = this._beziers[_loc3_][_loc2_][2];
  191.             }
  192.          }
  193.          else
  194.          {
  195.             for(_loc3_ in this._beziers)
  196.             {
  197.                _loc6_ = uint(this._beziers[_loc3_].length);
  198.                if(param1 < 0)
  199.                {
  200.                   _loc2_ = 0;
  201.                }
  202.                else if(param1 >= 1)
  203.                {
  204.                   _loc2_ = int(_loc6_ - 1);
  205.                }
  206.                else
  207.                {
  208.                   _loc2_ = int(_loc6_ * param1);
  209.                }
  210.                _loc5_ = (param1 - _loc2_ * (1 / _loc6_)) * _loc6_;
  211.                _loc4_ = this._beziers[_loc3_][_loc2_];
  212.                if(this.round)
  213.                {
  214.                   _loc7_ = _loc4_[0] + _loc5_ * (2 * (1 - _loc5_) * (_loc4_[1] - _loc4_[0]) + _loc5_ * (_loc4_[2] - _loc4_[0]));
  215.                   this._target[_loc3_] = _loc7_ > 0 ? int(_loc7_ + 0.5) : int(_loc7_ - 0.5);
  216.                }
  217.                else
  218.                {
  219.                   this._target[_loc3_] = _loc4_[0] + _loc5_ * (2 * (1 - _loc5_) * (_loc4_[1] - _loc4_[0]) + _loc5_ * (_loc4_[2] - _loc4_[0]));
  220.                }
  221.             }
  222.          }
  223.          if(this._orient)
  224.          {
  225.             _loc2_ = int(this._orientData.length);
  226.             _loc8_ = {};
  227.             while(_loc2_--)
  228.             {
  229.                _loc11_ = this._orientData[_loc2_];
  230.                _loc8_[_loc11_[0]] = this._target[_loc11_[0]];
  231.                _loc8_[_loc11_[1]] = this._target[_loc11_[1]];
  232.             }
  233.             _loc13_ = this._target;
  234.             _loc14_ = this.round;
  235.             this._target = this._future;
  236.             this.round = false;
  237.             this._orient = false;
  238.             _loc2_ = int(this._orientData.length);
  239.             while(_loc2_--)
  240.             {
  241.                _loc11_ = this._orientData[_loc2_];
  242.                this.changeFactor = param1 + (_loc11_[4] || 0.01);
  243.                _loc12_ = Number(Number(_loc11_[3]) || 0);
  244.                _loc9_ = this._future[_loc11_[0]] - _loc8_[_loc11_[0]];
  245.                _loc10_ = this._future[_loc11_[1]] - _loc8_[_loc11_[1]];
  246.                _loc13_[_loc11_[2]] = Math.atan2(_loc10_,_loc9_) * _RAD2DEG + _loc12_;
  247.             }
  248.             this._target = _loc13_;
  249.             this.round = _loc14_;
  250.             this._orient = true;
  251.          }
  252.       }
  253.    }
  254. }
  255.  
  256.