📄 lineargo.as
字号:
} /** * A LinearGoRepeater instance that defines options for repeated * or back-and-forth cycling animation. * * <p>You may pass a LinearGoRepeater instance to the constructor's * repeater parameter to set all options at instantiation. The * repeater's cycles property can be set to an integer, or * to Repeater.INFINITE or 0 to repeat indefinitely, and checked using * <code>linearGo.repeater.currentCycle</code>. LinearGoRepeater's * <code>reverseOnCycle</code> flag is true by default, which * causes animation to cycle back and forth. In that mode you can * also specify a separate easing function (plus extraEasingParams) * to use for the reverse animation cycle. For example, an easeOut * easing with an easeIn easingOnCycle will produce a more * natural-looking result. If <code>reverseOnCycle</code> is disabled, * the animation will repeat its play forward each time.</p> * * <p>(The repeater property replaces the cycles, easeOnCycle and * currentCycle parameters in earlier releases of LinearGo).</p> * * @see org.goasap.managers.LinearGoRepeater LinearGoRepeater */ public function get repeater(): LinearGoRepeater { return _repeater; } /** * When useFrames mode is activated, duration and delay are treated * as update-counts instead of time values. * * <p>(This mode is normally only used for specialty situations.)</p> * * <p>Using this feature with a pulseInterval of GoEngine.ENTER_FRAME * will result in a frame-based update that mimics the behavior of the * flash timeline. As with the timeline, frame-based tween durations can * vary based on the host computer's processor load and other factors.</p> * * <p>The <code>setupUseFramesMode()</code> class method is a much easier * way to use frames in your project, instead of setting this property * on every tween individually.</p> * * @see #setupUseFramesMode() */ public function set useFrames(value:Boolean):void { if (_state==STOPPED) _useFrames = value; } public function get useFrames():Boolean { return _useFrames; } /** * A number between 0 and 1 representing the current tween value. * * <p>Use this number as a multiplier to apply values to targets * across time.<p> * * <p>Here's an example of what an overridden update method might contain:</p> * <pre> * super.update(currentTime); * target[ propName ] = super.correctValue(startValue + change*_position); * </pre> * @see #timePosition */ public function get position():Number { return _position; } /** * For time-based tweens, returns a time value which is negative during delay * then spans the tween duration in positive values, ignoring repeat cycles. * * <p>In useFrames mode, this getter differs from <code>currentFrame</code> * significantly. Instead of constantly increasing through all cycles as if * tweens were back-to-back in a timeline layer, this method acts more like * a single tween placed at frame 1, with a timeline playhead that scans back * and forth or loops during cycles. So for a 10-frame tween with a 5-frame * delay and 2 repeater cycles with reverseOnCycle set to true, this method * will return values starting at -5, start the animation at 1, play to 10 * then step backward to 1 again.</p> * * @see #position * @see #currentFrame * @see #duration * @see #delay * @see #setupUseFramesMode() */ public function get timePosition():Number { if (_state==STOPPED) return 0; var mult:Number = Math.max(0, timeMultiplier); if (_useFrames) { if (_currentFrame>_framesBase) { var cf:uint = _currentFrame-_framesBase; if (_repeater.direction==-1) { return ((_duration-1) - cf%_duration) + _framesBase; } return cf%_duration + _framesBase; } return _currentFrame; } return ((getTimer()-_startTime) / 1000 / mult); } /** * Returns the number of updates that have occured since start. * * <p>This update-count property does not necessarily correspond * to the actual player framerate, just the instance's pulseInterval.</p> * * <p>This property is set up to mirror the flash timeline. Imagine a timeline * layer with a delay being a set of blank frames followed by the tween, * followed by subsequent cycles as additional tweens: this is the way * the <code>currentFrame</code> property works. Its first value is 1 by * default, which can be changed to 0 in <code>setupUseFramesMode()</code>. * This differs significantly from <code>timePosition</code>, which places * the start of a single instance of the tween at frame 1 and steps its * values from negative during delay then cycling through the single tween.</p> * * * @see #useFrames * @see #setupUseFramesMode() * @see #timePosition */ public function get currentFrame():uint { return _currentFrame; } // -== Protected Properties ==- /** @private */ protected static var _useFramesMode : Boolean = false; /** @private */ protected static var _framesBase : Number = 1; /** @private */ protected var _delay : Number; /** @private */ protected var _duration : Number; /** @private */ protected var _tweenDuration : Number; /** @private */ protected var _easing : Function; /** @private */ protected var _easeParams : Array; /** @private */ protected var _extraEaseParams : Array; /** @private */ protected var _repeater : LinearGoRepeater; /** @private */ protected var _currentEasing : Function; /** @private */ protected var _useFrames : Boolean; /** @private */ protected var _started : Boolean = false; /** @private */ protected var _currentFrame : int; /** @private */ protected var _position : Number; /** @private */ protected var _change : Number; /** @private */ protected var _startTime : Number; /** @private */ protected var _endTime : Number; /** @private */ protected var _pauseTime : Number; /** @private */ protected var _callbacks : Object = new Object(); // In tests, creating this object up front is more efficient. // -== Public Methods ==- /** * The inputs here are not a convention, subclasses should design * their own constructors appropriate to usage. They are provided * here primarily as a convenience for subclasses. However, do not * omit calling super() from subclass constructors: LinearGo's * constructor sets and validates class defaults and sets up the * repeater instance. */ public function LinearGo( delay : Number=NaN, duration : Number=NaN, easing : Function=null, extraEasingParams : Array=null, repeater : LinearGoRepeater=null, useRelative : Boolean=false, useRounding : Boolean=false, useFrames : Boolean=false, pulseInterval : Number=NaN ) { // validate & set class defaults first if (isNaN(defaultDelay)) defaultDelay = 0; if (isNaN(defaultDuration)) defaultDuration = 1; try { this.easing = defaultEasing; } catch (e1:EasingFormatError) { defaultEasing = easeOut; } // set params if (!isNaN(delay)) _delay = delay; else _delay = defaultDelay; if (!isNaN(duration)) _duration = duration; else _duration = defaultDuration; try { this.easing = easing; } catch (e2:EasingFormatError) { if (easing!=null) { throw e2; } // user passed invalid easing function this.easing = defaultEasing; } if (extraEasingParams) _extraEaseParams = extraEasingParams; if (useRelative) this.useRelative = true; if (useRounding) this.useRounding = true; _useFrames = (useFrames || _useFramesMode); if (!isNaN(pulseInterval)) _pulse = pulseInterval; if (repeater!=null) _repeater = repeater; // repeater setup makes super() call important for all subclasses. else _repeater = new LinearGoRepeater(); _repeater.setParent(this); } /** * Starts play for this LinearGo instance using GoEngine. * * <p>CONVENTION ALERT: If <code>useRelative</code> is true, calculate tween values * relative to the target object's existing value as in the example below.</p> * * <p>Most typically you should also store the tween's start and change values * for later use in <code>onUpdate</code>.</p> * * <pre> * protected var _target : DisplayObject; * protected var _width : Number; * protected var _changeWidth : Number; * * public function start():Boolean * { * if (!_target || !_width || isNaN(_width)) * return false; * * _startWidth = _target.width; * * if (useRelative) { * _changeWidth = _width; * } else { * _changeWidth = (_width - _startWidth); * } * * return (super.start()); * } * </pre> * * @return Successful addition of the item to GoEngine * * @see GoItem#useRelative * @see #onUpdate() */ public function start() : Boolean { stop(); // does nothing if already stopped. if (GoEngine.addItem(this)==false) return false; reset(); _state = (_delay > 0 ? PLAYING_DELAY : PLAYING); // has to be set here since delay is not included in PlayableBase. // note: start event is dispatched on the first update cycle for tighter cross-item syncing. return true; } /** * Ends play for this LinearGo instance and dispatches a GoEvent.STOP * event if the tween is incomplete. This method does not typically * require subclassing.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -