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

📄 tweengroup.as

📁 一个地图flash应用
💻 AS
📖 第 1 页 / 共 3 页
字号:
				_initTime += ms;
				
				if (this.expired && this.endTime > time) {
					this.expired = false;
					_unexpired[_unexpired.length] = this;
				}
			}
		}
		
		protected function renderTween($tween:TweenLite, $time:Number):void {
			var end:Number = getEndTime($tween), renderTime:Number, isPaused:Boolean;
			if ($tween.startTime == 999999999999999) {
				$tween.startTime = $tween.initTime + ($tween.delay * (1000 / $tween.combinedTimeScale)); //this forces paused tweens with false start times to adjust to the normal one temporarily so that we can render it properly.
				isPaused = true;
			}
			if (!$tween.initted) {
				var active:Boolean = $tween.active;
				$tween.active = false; 
				if (isPaused) {
					$tween.initTweenVals();
					if ($tween.vars.onStart != null) {
						$tween.vars.onStart.apply(null, $tween.vars.onStartParams);
					}
				} else {
					$tween.activate(); //triggers the initTweenVals and fires the onStart() if necessary
				}
				$tween.active = active;
			}
			
			if ($tween.startTime > $time) { //don't allow tweens with delays that haven't expired yet to be active
				renderTime = $tween.startTime;
			} else if (end < $time) {
				renderTime = end;
			} else {
				renderTime = $time;
			}
			
			if (renderTime < 0) { //render time is uint, so it must be zero or greater. 
				var originalStart:Number = $tween.startTime;
				$tween.startTime -= renderTime;
				$tween.render(0);
				$tween.startTime = originalStart;
			} else {
				$tween.render(renderTime);
			}
			
			if (isPaused) {
				$tween.startTime = 999999999999999;
			}
		}
		
		/**
		 * If there are multiple tweens in the same group that control the same property of the same property, we need to make sure they're rendered in the correct
		 * order so that the one(s) closest in proximity to the current time is rendered last. Feed this function an Array of tweens and the time and it'll return
		 * an Array with them in the correct render order.
		 *  
		 * @param $tweens An Array of tweens to get in the correct render order
		 * @param $time Time (in milliseconds) which defines the proximity point for each tween (typically the render time)
		 * @return An Array with the tweens in the correct render order
		 */
		protected function getRenderOrder($tweens:Array, $time:Number):Array {
			var i:int, tween:TweenLite, startTime:Number, postTweens:Array = [], preTweens:Array = [], a:Array = [];
			for (i = $tweens.length - 1; i > -1; i--) {
				startTime = getStartTime($tweens[i]);
				if (startTime >= $time) {
					postTweens[postTweens.length] = {start:startTime, tween:$tweens[i]};
				} else {
					preTweens[preTweens.length] = {end:getEndTime($tweens[i]), tween:$tweens[i]};
				}
			}
			postTweens.sortOn("start", Array.NUMERIC);
			preTweens.sortOn("end", Array.NUMERIC);
			for (i = postTweens.length - 1; i > -1; i--) {
				a[i] = postTweens[i].tween;
			}
			for (i = preTweens.length - 1; i > -1; i--) {
				a[a.length] = preTweens[i].tween;
			}
			return a;
		}
		
		protected function pauseTween($tween:TweenLite):void {
			if ($tween is _TweenMax) {
				($tween as Object).pauseTime = _pauseTime;
			} 
			$tween.startTime = 999999999999999; //for OverwriteManager
			$tween.enabled = false;
		}
		
		protected function resumeTween($tween:TweenLite):void {
			if ($tween is _TweenMax) {
				($tween as Object).pauseTime = NaN;
			}
			$tween.startTime = $tween.initTime + ($tween.delay * (1000 / $tween.combinedTimeScale));
		}
		
		protected function getEndTime($tween:TweenLite):Number {
			return $tween.initTime + (($tween.delay + $tween.duration) * (1000 / $tween.combinedTimeScale));
		}
		
		protected function getStartTime($tween:TweenLite):Number {
			return $tween.initTime + ($tween.delay * 1000 / $tween.combinedTimeScale);
		}
		
		protected function setTweenInitTime($tween:TweenLite, $initTime:Number):void {
			var offset:Number = $initTime - $tween.initTime;
			$tween.initTime = $initTime;
			if ($tween.startTime != 999999999999999) { //required for OverwriteManager (indicates a tween has been paused)
				$tween.startTime += offset;
			}
		}
		
		protected function setTweenStartTime($tween:TweenLite, $startTime:Number):void {
			var offset:Number = $startTime - getStartTime($tween);
			$tween.initTime += offset;
			if ($tween.startTime != 999999999999999) { //required for OverwriteManager (indicates a tween has been paused)
				$tween.startTime = $startTime;
			}
		}
		
		protected function getProgress($includeDelay:Boolean=false):Number {
			if (_tweens.length == 0) {
				return 0;
			} else {
				var time:Number = (isNaN(_pauseTime)) ? TweenLite.currentTime : _pauseTime;
				var min:Number = ($includeDelay) ? _initTime : _startTime;
				var p:Number = (time - min) / (this.endTime - min);
				if (p < 0) {
					return 0;
				} else if (p > 1) {
					return 1;
				} else {
					return p;
				}
			}
		}
		
		protected function setProgress($progress:Number, $includeDelay:Boolean=false):void {
			if (_tweens.length != 0) {
				var time:Number = (isNaN(_pauseTime)) ? TweenLite.currentTime : _pauseTime;
				var min:Number = ($includeDelay) ? _initTime : _startTime;
				offsetTime(_tweens, (time - (min + ((this.endTime - min) * $progress))) / 1000);
			}
		}
		
		public function handleCompletion():void {
			if (!isNaN(this.yoyo) && (_repeatCount < this.yoyo || this.yoyo == 0)) {
				_repeatCount++;
				reverse(true);
			} else if (!isNaN(this.loop) && (_repeatCount < this.loop || this.loop == 0)) {
				_repeatCount++;
				setProgress(0, true);
			}
			if (this.onComplete != null) {
				this.onComplete.apply(null, this.onCompleteParams);
			}
			_dispatcher.dispatchEvent(new Event(Event.COMPLETE));
		}
		
		
		
//---- GETTERS / SETTERS --------------------------------------------------------------------------------------------------
		
		/**
		 * @return Number of tweens in the group 
		 */
		public function get length():uint {
			return _tweens.length;
		}
		
		/**
		 * @return Overall progress of the group of tweens (not including any initial delay) as represented numerically between 0 and 1 where 0 means the group hasn't started, 0.5 means it is halfway finished, and 1 means it has completed.
		 */
		public function get progress():Number {
			return getProgress(false);
		}
		/**
		 * Controls the overall progress of the group of tweens (not including any initial delay) as represented numerically between 0 and 1.
		 * 
		 * @param $n Overall progress of the group of tweens (not including any initial delay) as represented numerically between 0 and 1 where 0 means the group hasn't started, 0.5 means it is halfway finished, and 1 means it has completed.
		 */
		public function set progress($n:Number):void {
			setProgress($n, false);
		}
		
		/**
		 * @return Overall progress of the group of tweens (including any initial delay) as represented numerically between 0 and 1 where 0 means the group hasn't started, 0.5 means it is halfway finished, and 1 means it has completed.
		 */
		public function get progressWithDelay():Number {
			return getProgress(true);
		}
		/**
		 * Controls the overall progress of the group of tweens (including any initial delay) as represented numerically between 0 and 1.
		 * 
		 * @param $n Overall progress of the group of tweens (including any initial delay) as represented numerically between 0 and 1 where 0 means the group hasn't started, 0.5 means it is halfway finished, and 1 means it has completed.
		 */
		public function set progressWithDelay($n:Number):void {
			setProgress($n, true);
		}
		
		/**
		 * @return Duration (in seconds) of the group of tweens NOT including any initial delay
		 */
		public function get duration():Number {
			if (_tweens.length == 0) {
				return 0;
			} else {
				return (this.endTime - _startTime) / 1000;
			}
		}
		/**
		 * @return Duration (in seconds) of the group of tweens including any initial delay
		 */
		public function get durationWithDelay():Number {
			if (_tweens.length == 0) {
				return 0;
			} else {
				return (this.endTime - _initTime) / 1000;
			}
		}
		
		/**
		 * @return If the group of tweens is paused, this value will be true. Otherwise, it will be false.
		 */
		public function get paused():Boolean {
			return (!isNaN(_pauseTime));
		}
		/**
		 * Sets the paused state of the group of tweens
		 * 
		 * @param $b Sets the paused state of the group of tweens.
		 */
		public function set paused($b:Boolean):void {
			if ($b) {
				pause();
			} else {
				resume();
			}
		}
		
		/**
		 * @return If the group of tweens is reversed, this value will be true. Otherwise, it will be false.
		 */
		public function get reversed():Boolean {
			return _reversed;
		}
		/**
		 * Sets the reversed state of the group of tweens
		 * 
		 * @param $b Sets the reversed state of the group of tweens.
		 */
		public function set reversed($b:Boolean):void {
			if (_reversed != $b) {
				reverse(true);
			}
		}
		
		/**
		 * @return Alignment of the tweens within the group. possible values are "sequence", "start", "end", "init", and "none"
		 */
		public function get align():String {
			return _align;
		}
		/**
		 * Controls the alignment of the tweens within the group. Typically it's best to use the constants TweenGroup.ALIGN_SEQUENCE, TweenGroup.ALIGN_START, TweenGroup.ALIGN_END, TweenGroup.ALIGN_INIT, or TweenGroup.ALIGN_NONE
		 * 
		 * @param $s Sets the alignment of the tweens within the group. Typically it's best to use the constants TweenGroup.ALIGN_SEQUENCE, TweenGroup.ALIGN_START, TweenGroup.ALIGN_END, TweenGroup.ALIGN_INIT, or TweenGroup.ALIGN_NONE
		 */
		public function set align($s:String):void {
			_align = $s;
			realign();
		}
		
		/**
		 * @return Amount of time (in seconds) to offset each tween according to the current alignment. For example, if the align property is set to ALIGN_SEQUENCE and stagger is 0.5, this adds 0.5 seconds between each tween in the sequence. If align is set to ALIGN_START, it would add 0.5 seconds to the start time of each tween (0 for the first tween, 0.5 for the second, 1 for the third, etc.)
		 */
		public function get stagger():Number {
			return _stagger;
		}
		/**
		 * Controls the amount of time (in seconds) to offset each tween according to the current alignment. For example, if the align property is set to ALIGN_SEQUENCE and stagger is 0.5, this adds 0.5 seconds between each tween in the sequence. If align is set to ALIGN_START, it would add 0.5 seconds to the start time of each tween (0 for the first tween, 0.5 for the second, 1 for the third, etc.)
		 * 
		 * @param $s Amount of time (in seconds) to offset each tween according to the current alignment. For example, if the align property is set to ALIGN_SEQUENCE and stagger is 0.5, this adds 0.5 seconds between each tween in the sequence. If align is set to ALIGN_START, it would add 0.5 seconds to the start time of each tween (0 for the first tween, 0.5 for the second, 1 for the third, etc.)
		 */
		public function set stagger($n:Number):void {
			_stagger = $n;
			realign();
		}
		
		/**
		 * @return An Array of the tweens in this TweenGroup (this could be used to concat() with another TweenGroup for example) 
		 */
		public function get tweens():Array {
			return _tweens.slice();
		}
		
	}
}
	
import gs.TweenLite;

internal class ReverseProxy {
	private var _tween:TweenLite;
	
	public function ReverseProxy($tween:TweenLite) {
		_tween = $tween;
	}
	
	public function reverseEase($t:Number, $b:Number, $c:Number, $d:Number):Number {
		return _tween.vars.ease($d - $t, $b, $c, $d);
	}
	
}

⌨️ 快捷键说明

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