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

📄 lineargo.as

📁 jquery插件
💻 AS
📖 第 1 页 / 共 3 页
字号:
		 * 		 * @return Successful removal of the item from GoEngine		 */		public function stop() : Boolean {			if (_state==STOPPED || GoEngine.removeItem(this)==false)				return false;			_state = STOPPED;			var completed:Boolean = (_easeParams!=null && _position==_easeParams[1]+_change);			reset();			if (!completed) // otherwise a COMPLETE event was dispatched.				dispatch( GoEvent.STOP );			return true;		}		/**		 * Pauses play (including delay) for this LinearGo instance.		 * This method does not typically require subclassing.		 * 		 * @return Success		 * @see #resume()		 * @see org.goasap.GoEngine#setPaused GoEngine.setPaused()		 */		public function pause() : Boolean {			if (_state==STOPPED || _state==PAUSED)				return false;			_state = PAUSED;			_pauseTime = (_useFrames ? _currentFrame : getTimer()); // This causes update() to skip processing.			dispatch(GoEvent.PAUSE);			return true;		}				/**		 * Resumes previously paused play, including delay.		 * This method does not typically require subclassing.		 * 		 * @return Success		 * @see #pause()		 * @see org.goasap.GoEngine#setPaused GoEngine.setPaused()		 */		public function resume() : Boolean {			if (_state != PAUSED)				return false;			var currentTime:Number = (_useFrames ? _currentFrame : getTimer());			setup(currentTime - (_pauseTime - _startTime)); 			_pauseTime = NaN;			_state = (_startTime > currentTime ? PLAYING_DELAY : PLAYING);			dispatch(GoEvent.RESUME);			return true;		}				/**		 * Skips to a point in the tween's duration and plays, from any state. 		 * This method does not typically require subclassing.		 * 		 * <p>If GoItem.timeMultiplier is set to a custom value, you should still pass a 		 * seconds value based on the tween's real duration setting.</p>		 * 		 * @param time		Seconds or frames to jump to across all cycles, where 0 (or 1 in useFramesMode)		 * 					represents tween start, numbers greater than duration represent higher repeat cycles,		 * 					and negative numbers represent a new delay to play before tween start.		 * @return Success		 * @see #timePosition		 */		public function skipTo(time : Number) : Boolean 		{			if (_state==STOPPED) {				if (start()==false) 					return false;			}			if (isNaN(time)) { time = 0; }			var mult:Number = Math.max(0, timeMultiplier) * (_useFrames ? 1 : 1000);			var startTime:Number;			var currentTime:Number;			if (time < _framesBase) { // Negative value: rewind and add a new delay.				_repeater.reset();				if (_position>0) { skipTo(_framesBase); } // skips to start so new pause occurs in starting position			}			else {				time = _repeater.skipTo(_duration, time-_framesBase); // sets cycles and returns new position			}			if (_useFrames) {				startTime = _framesBase;				currentTime = _currentFrame = Math.round(time*mult);			}			else {				currentTime = getTimer();				startTime = (currentTime - (time * mult)); // skipTo operation is performed by altering the tween's start & end times.			}			setup(startTime);			_state = (_startTime > currentTime ? PLAYING_DELAY : PLAYING);			update(currentTime); // sets _position			return true;		}				/**		 * An alternative to subscribing to events is to store callbacks. You can 		 * associate any number of callbacks with the primary GoEvent types START,		 * UPDATE, COMPLETE, and STOP (only fired if the tween is stopped before it 		 * completes).		 * 		 * <p>		 * Note that there is little difference between using callbacks and events.		 * Both are common techniques used in many various modern tweening APIs. Callbacks 		 * are slightly faster, but this won't normally be noticeable unless thousands of 		 * tweens are being run at once.		 * </p>		 * 		 * @param closure	A reference to a callback function		 * @param type		Any GoEvent type constant, the default is COMPLETE.		 * @see #removeCallback		 * @see org.goasap.events.GoEvent GoEvent		 */		public function addCallback(closure : Function, type : String=GoEvent.COMPLETE):void {			if (!_callbacks[ type ]) 				_callbacks[ type ] = new Array();			var a:Array = (_callbacks[ type ] as Array);			if (a.indexOf(closure)==-1)				a.push(closure);		}				/**		 * Removes a method closure previously stored using addCallback.		 * 		 * @param closure	A reference to a function		 * @param type		A GoEvent constant, default is COMPLETE.		 * @see #addCallback		 * @see org.goasap.events.GoEvent GoEvent		 */		public function removeCallback(closure : Function, type : String=GoEvent.COMPLETE):void {			var a:Array = (_callbacks[ type ] as Array);			if (a) 				while (a.indexOf(closure)>-1)					a.splice(a.indexOf(closure), 1);		}				/**		 * Performs tween calculations on GoEngine pulse.		 * 		 * <p>Subclass <code>onUpdate</code> instead of this method.		 * 		 * @param currentTime	Clock time for the current block of updates.		 * @see #onUpdate()		 */		override public function update(currentTime:Number) : void 		{			if (_state==PAUSED)				return;						_currentFrame ++;			if (_useFrames) 				currentTime = _currentFrame;						if (isNaN(_startTime))		// setup() must be called once prior to tween's 1st update. 				setup(currentTime);		// This is done here, not in start, for tighter syncing of items.						if (_startTime > currentTime) 				return; // still PLAYING_DELAY						// (1.) Set _position and determine primary update type.			var type:String = GoEvent.UPDATE;			if (currentTime < _endTime) { // start, update...				if (!_started)					type = GoEvent.START;				_easeParams[0] = (currentTime - _startTime);				_position = _currentEasing.apply(null, _easeParams); // update position using easing function			}			else { // complete, cycle...				_position = _easeParams[1] + _change; // set absolute 1 or 0 position at end of cycle				type = (_repeater.hasNext() ? GoEvent.CYCLE : GoEvent.COMPLETE);			}						// (2.) Run onUpdate() passing the primary update type, then			// (3.) dispatch up to three events in correct order.			onUpdate(type);			if (!_started) {				_state = PLAYING;				_started = true;				dispatch(GoEvent.START);			}			dispatch(GoEvent.UPDATE);			if (type==GoEvent.COMPLETE) {				stop();				dispatch(GoEvent.COMPLETE);			}			else if (type==GoEvent.CYCLE) {				_repeater.next();				dispatch(GoEvent.CYCLE);				_startTime = NaN; // causes setup() to be called again on next update to prep next cycle.			}		}				// -== Protected Methods ==-				/**		 * Subclass this method (instead of the update method) for simplicity. 		 * 		 * <p>Use this method to manipulate targets based on the current _position 		 * setting, which is a 0-1 multiplier precalculated to the tween's position		 * based on its easing style and the current time in the tween.</p> 		 * 		 * <p>CONVENTION ALERT: To implement the Go convention <code>useRounding</code>,		 * always call GoItem's <code>correctValue()</code> method on each calculated 		 * tween value before you apply it to a target. This corrects NaN to 0 and 		 * rounds the value if <code>useRounding</code> is true.</p>		 * 		 * Example:		 * <pre>		 * override protected function onUpdate(type:String):void		 * {		 *     target[ propName ] = super.correctValue(startValue + change*_position);		 * }		 * </pre>		 * 		 * @param type	A constant from the class GoEvent: START, UPDATE, CYCLE, or COMPLETE.		 * @see GoItem#correctValue()		 * @see GoItem#useRounding		 * @see #update()		 */		protected function onUpdate(type : String) : void 		{			// Subclass this method and start to implement your tween class.		}				/**		 * @private		 * Internal setup routine used by start() and other methods.		 * 		 * @param time			Tween start time based on getTimer		 */		protected function setup(startTime : Number) : void 		{			_startTime = startTime;			var mult:Number = Math.max(0, timeMultiplier) * (_useFrames ? 1 : 1000);			_tweenDuration = (_useFrames ? Math.round(_duration * mult)-1 : (_duration * mult));			_endTime = _startTime + _tweenDuration;			if (!_started) {				var d:Number = (_useFrames ? Math.round(_delay * mult) : (_delay * mult));				_startTime += d;				_endTime += d;			}			// Set up a tween cycle: _currentEasing, _change, _position, and _easeParams. 			// Be sure _repeater is updated before this call so the next cycle gets set up.			var useCycleEase:Boolean = _repeater.currentCycleHasEasing;  			_currentEasing = (useCycleEase ? _repeater.easingOnCycle : _easing);			var extras:Array = (useCycleEase ? _repeater.extraEasingParams : _extraEaseParams);			_change = _repeater.direction;			_position = (_repeater.direction==-1 ? 1 : 0);			_easeParams = new Array(0, _position, _change, _tweenDuration); // stored to reduce runtime object-creation			if (extras) _easeParams = _easeParams.concat(extras);		}				/**		 * @private		 * Internal, dispatches events and executes callbacks of any pre-verified type.		 *  		 * @param type	Verified in addCallback, not in this method.		 * @see #org.goasap.events.GoEvent GoEvent		 */		protected function dispatch(type:String):void 		{			var a:Array = (_callbacks[ type ] as Array);			if (a)				for each (var callback:Function in a)					callback();			if (hasEventListener(type))				dispatchEvent(new GoEvent( type ));		}				/**		 * @private		 */		protected function reset() : void {			_position = 0;			_change = 1;			_repeater.reset();			_currentFrame = _framesBase-1;			_currentEasing = _easing;			_easeParams = null;			_started = false;			_pauseTime = NaN;			_startTime = NaN;		}	}}

⌨️ 快捷键说明

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