⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tweenlite.as

📁 一个地图flash应用
💻 AS
📖 第 1 页 / 共 3 页
字号:
			$vars.runBackwards = true;
			return new TweenLite($target, $duration, $vars);
		}
		
		public static function delayedCall($delay:Number, $onComplete:Function, $onCompleteParams:Array = null):TweenLite {
			return new TweenLite($onComplete, 0, {delay:$delay, onComplete:$onComplete, onCompleteParams:$onCompleteParams, overwrite:0});
		}
		
		public function render($t:uint):void {
			var time:Number = ($t - this.startTime) * 0.001, factor:Number, tp:Object, i:int;
			if (time >= this.duration) {
				time = this.duration;
				factor = (this.ease == this.vars.ease || this.duration == 0.001) ? 1 : 0; //to accommodate TweenLiteGroup.reverse(). Without this, the last frame would render incorrectly
			} else {
				factor = this.ease(time, 0, 1, this.duration);
			}
			for (i = this.tweens.length - 1; i > -1; i--) {
				tp = this.tweens[i];
				tp[0][tp[1]] = tp[2] + (factor * tp[3]); //tween index values: [object, property, start, change, name]
			}
			if (_hst) { //has sub-tweens
				for (i = _subTweens.length - 1; i > -1; i--) {
					_subTweens[i].proxy(_subTweens[i], time);
				}
			}
			if (_hasUpdate) {
				this.vars.onUpdate.apply(null, this.vars.onUpdateParams);
			}
			if (time == this.duration) {
				complete(true);
			}
		}
		
		public static function updateAll($e:Event = null):void {
			var t:uint = currentTime = getTimer(), ml:Dictionary = masterList, a:Array, i:int, tween:TweenLite;
			for each (a in ml) {
				for (i = a.length - 1; i > -1; i--) {
					tween = a[i];
					if (tween == null) {
						//ignore
					} else if (tween.active) {
						tween.render(t);
					} else if (tween.gc) {
						a.splice(i, 1);
					} else if (t >= tween.startTime) {
						tween.activate();
						tween.render(t);
					}
				}
			}
		}
		
		public function activate():void {
			this.started = this.active = true;
			if (!this.initted) {
				initTweenVals();
			}
			if (this.vars.onStart != null) {
				this.vars.onStart.apply(null, this.vars.onStartParams);
			}
			if (this.duration == 0.001) { //In the constructor, if the duration is zero, we shift it to 0.001 because the easing functions won't work otherwise. We need to offset the this.startTime to compensate too.
				this.startTime -= 1;
			}
		}
		
		public function complete($skipRender:Boolean = false):void {
			if (!$skipRender) {
				if (!this.initted) {
					initTweenVals();
				}
				this.startTime = currentTime - (this.duration * 1000) / this.combinedTimeScale;
				render(currentTime); //Just to force the final render
				return;
			}
			if (this.vars.persist != true) {
				this.enabled = false; //moved above the onComplete callback in case there's an error in the user's onComplete - this prevents constant errors
			}
			if (this.vars.onComplete != null) {
				this.vars.onComplete.apply(null, this.vars.onCompleteParams);
			}
		}
		
		public static function removeTween($t:TweenLite, $clear:Boolean = true):void {
			if ($t != null) {
				if ($clear) { 
					$t.clear();
				}
				$t.enabled = false;
			}
		}
	
		public function clear():void {
			this.tweens = [];
			_subTweens = [];
			this.vars = {};
			_hst = _hasUpdate = false;
		}
		
		public static function killTweensOf($target:Object = null, $complete:Boolean = false):void {
			if ($target != null && masterList[$target] != undefined) {
				var a:Array = masterList[$target], i:int, tween:TweenLite;
				for (i = a.length - 1; i > -1; i--) {
					tween = a[i];
					if ($complete && !tween.gc) {
						tween.complete(false);
					}
					tween.clear(); //prevents situations where a tween is killed but is still referenced elsewhere and put back in the render queue, like if a TweenLiteGroup is paused, then the tween is removed, then the group is unpaused.
				}
				delete masterList[$target];
			}
		}
		
		public function killVars($vars:Object):void {
			if (overwriteManager.enabled) {
				overwriteManager.killVars($vars, this.vars, this.tweens, _subTweens, []);
			}
		}
		
		protected static function killGarbage($e:TimerEvent):void {
			var ml:Dictionary = masterList, tgt:Object, a:Array;
			for (tgt in ml) {
				if (ml[tgt].length == 0) {
					delete ml[tgt];
				}
			}
		}
		
		public static function easeOut($t:Number, $b:Number, $c:Number, $d:Number):Number {
			return -$c * ($t /= $d) * ($t - 2) + $b;
		}
		
//---- PROXY FUNCTIONS ------------------------------------------------------------------------
		
		protected function easeProxy($t:Number, $b:Number, $c:Number, $d:Number):Number { //Just for when easeParams are passed in via the vars object.
			return this.vars.proxiedEase.apply(null, arguments.concat(this.vars.easeParams));
		}
		public static function tintProxy($o:Object, $time:Number=0):void {
			var n:Number = $o.target.progress, r:Number = 1 - n, sc:Object = $o.info.color, ec:Object = $o.info.endColor;
			$o.info.target.transform.colorTransform = new ColorTransform(sc.redMultiplier * r + ec.redMultiplier * n,
																		  sc.greenMultiplier * r + ec.greenMultiplier * n,
																		  sc.blueMultiplier * r + ec.blueMultiplier * n,
																		  sc.alphaMultiplier * r + ec.alphaMultiplier * n,
																		  sc.redOffset * r + ec.redOffset * n,
																		  sc.greenOffset * r + ec.greenOffset * n,
																		  sc.blueOffset * r + ec.blueOffset * n,
																		  sc.alphaOffset * r + ec.alphaOffset * n);
		}
		public static function frameProxy($o:Object, $time:Number=0):void {
			$o.info.target.gotoAndStop(Math.round($o.target.frame));
		}
		public static function volumeProxy($o:Object, $time:Number=0):void {
			$o.info.target.soundTransform = $o.target;
		}
		public static function visibleProxy($o:Object, $time:Number):void { //broken out as a subTween proxy instead of some conditional code in the complete() and constructor so that if render() is called to arbitrarily render a time other than currentTime, the visibility will be correct. This can happen in TweenGroup for example.
			var t:TweenLite = $o.info.tween;
			if (t.duration == $time) {
				if (t.vars.runBackwards != true && t.ease == t.vars.ease) { //t.ease == t.vars.ease checks to make sure the tween wasn't reversed with a TweenGroup
					t.target.visible = t.vars.visible;
				}
			} else if (t.target.visible != true) {
				t.target.visible = true;
			}
		}
		
		
//---- GETTERS / SETTERS -----------------------------------------------------------------------
		
		public function get enabled():Boolean {
			return (this.gc) ? false : true;
		}
		
		public function set enabled($b:Boolean):void {
			if ($b) {
				if (masterList[this.target] == undefined) {
					masterList[this.target] = [this];
				} else {
					var a:Array = masterList[this.target], found:Boolean, i:int;
					for (i = a.length - 1; i > -1; i--) {
						if (a[i] == this) {
							found = true;
							break;
						}
					}
					if (!found) {
						masterList[this.target].push(this);
					}
				}
			}
			this.gc = ($b) ? false : true;
			if (this.gc) {
				this.active = false;
			} else {
				this.active = this.started;
			}
		}
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -