| Package | org.goasap.items |
| Class | public class LinearGo |
| Inheritance | LinearGo GoItem PlayableBase flash.events.EventDispatcher |
| Implements | IPlayable |
LinearGo: A very simple tween
A LinearGo instance is a playable object that animates a single number. It dispatches events
and callbacks associated with the animation's start, update and completion. Instances can be used
directly, or easily subclassed to build custom tweening APIs. LinearGo extends GoItem, which
provides basic settings shared by physics and tween items. These include a state property,
pulseInterval, and the two common animation options useRounding and
useRelative.
The tween can be customized using the instance properties duration, easing
and delay. The number crunched by a LinearGo is readable in its position
property. This number always starts at 0 and completes at 1, regardless of the tween's duration
or easing (those parameters are factored in to produce accurate fractional in-between values).
As the tween runs, you can use position as a multiplier to animate virtually anything:
motion, alpha, a sound level, the values in a ColorTransform, BitmapFilter, a 3D scene, and so on.
Note that at times position may be less than 0 or greater than 1 depending on the easing function.
The START event occurs just before the first update (after the delay). UPDATE is fired once on
every update pulse, and COMPLETE just after the final update. The STOP event is fired by LinearGo
only if a tween is stopped before it completes. Additional events are fired on PAUSE, RESUME and at
the end of each CYCLE if the tween plays more than one cycle. Besides standard events, you can store
callback functions (method-closures) using addCallback. Any number of callbacks can be
associated with each GoEvent type. This alternative to the standard event model was included in
LinearGo since it's a common feature of many modern tweening APIs, and very slightly more efficient
than standard events.
LinearGo can play multiple back-and-forth tween cycles or repeat forward-play any number of times.
This functionality is handled by the LinearGo's repeater instance, which has settings for
alternate easing on reverse-cycles, infinite cycling, plus currentCycle and done
state properties.
Subclassing to create custom tweens
Important: Store your custom tween classes in a package bearing your own classpath, not in the core package! This will help avoid confusion with other authors' work.
It's possible to build virtually any tweening API over LinearGo because all of the specifics are left up to you: target objects, tweenable properties, tween values — and importantly, the datatypes of all of these.
A basic subclass can be created in three steps: Gathering target & property information, subclassing the
start method to set up the tween, and finally subclassing the onUpdate method
to affect the tween. The first step, gathering tween target and property information, can be done by writing
getter/setter properties, customizing the constructor, or both. Consider various options such as allowing for
single vs. multiple target objects, open vs. specific tween properties, and so on. The next step, subclassing
start, involves figuring the tween's amount of change and implementing a standard Go convention,
useRelative. This option should enable the user to declare tween values as relative to existing
values instead of as fixed absolutes. In the final step, you subclass onUpdate to apply the tween,
using the _position calculated by this base class:
target[ propName ] = super.correctValue(start + change _position);
The helper method correctValue is provided in the superclass GoItem, to clean up NaN values
and apply rounding when useRounding is activated. That's it — events and callbacks are
dispatched by LinearGo, so subclasses can remain simple.
An optional fourth step will make your custom tween compatible with Go managers. To do this, implement the IManageable interface. (OverlapMonitor prevents different tween instances from handling the same property at once; you can build other managers as well.)
{In the game of Go a black or white stone is called a go-ishi.}| Property | Defined by | ||
|---|---|---|---|
| currentFrame : uint [read-only]
Returns the number of updates that have occured since start.
| LinearGo | ||
| defaultDelay : Number = 0 [static]
Class default for the instance property delay.
| LinearGo | ||
| defaultDuration : Number = 1 [static]
Class default for the instance property duration.
| LinearGo | ||
| defaultEasing : Function [static]
Class default for the instance property easing.
| LinearGo | ||
![]() | defaultPulseInterval : Number [static]
Class default for the instance property
pulseInterval. | GoItem | |
![]() | defaultUseRelative : Boolean = false [static]
Class default for the instance property
useRelative. | GoItem | |
![]() | defaultUseRounding : Boolean = false [static]
Class default for the instance property
useRounding. | GoItem | |
| delay : Number
Number of seconds after start() call that the LinearGo begins processing.
| LinearGo | ||
| duration : Number
Number of seconds the LinearGo takes to process.
| LinearGo | ||
| easing : Function
Any standard easing-equation function such as the ones found in
the Flash package fl.motion.easing or the flex package mx.effects.easing.
| LinearGo | ||
| extraEasingParams : Array
Additional parameters to pass to easing functions that accept more than four.
| LinearGo | ||
![]() | playableID : *
An arbitrary id value for the convenient identification of any
instance, automatically set to an instance count by this class.
| PlayableBase | |
| position : Number [read-only]
A number between 0 and 1 representing the current tween value.
| LinearGo | ||
![]() | pulseInterval : int
Required by IUpdatable: Defines the pulse on which
update is called. | GoItem | |
| repeater : LinearGoRepeater
[read-only]
A LinearGoRepeater instance that defines options for repeated
or back-and-forth cycling animation.
| LinearGo | ||
![]() | state : String
Returns a PlayStates constant.
| PlayableBase | |
![]() | timeMultiplier : Number = 1 [static]
Alters the play speed for instances of any subclass that factors
this value into its calculations, such as LinearGo.
| GoItem | |
| timePosition : Number [read-only]
For time-based tweens, returns a time value which is negative during delay
then spans the tween duration in positive values, ignoring repeat cycles.
| LinearGo | ||
| useFrames : Boolean | LinearGo | ||
![]() | useRelative : Boolean
CONVENTION ALERT: This property is considered a Go convention, and subclasses must implement
it individually. Indicates that values should be treated as relative instead of absolute.
| GoItem | |
![]() | useRounding : Boolean
CONVENTION ALERT: This property is considered a Go convention, and subclasses must
implement it individually by calling the correctValue() method on all calculated values
before applying them to targets.
The correctValue method fixes NaN's as 0 and applies Math.round if useRounding is active. | GoItem | |
| Method | Defined by | ||
|---|---|---|---|
|
LinearGo(delay:Number, duration:Number, easing:Function = null, extraEasingParams:Array = null, repeater:LinearGoRepeater = null, useRelative:Boolean = false, useRounding:Boolean = false, useFrames:Boolean = false, pulseInterval:Number)
The inputs here are not a convention, subclasses should design
their own constructors appropriate to usage.
| LinearGo | ||
|
addCallback(closure:Function, type:String):void
An alternative to subscribing to events is to store callbacks.
| LinearGo | ||
![]() |
correctValue(value:Number):Number
IMPORTANT: Subclasses need to implement this functionality
individually.
| GoItem | |
|
easeNone(t:Number, b:Number, c:Number, d:Number):Number
[static]
An alternative default easing with no acceleration.
| LinearGo | ||
|
easeOut(t:Number, b:Number, c:Number, d:Number):Number
[static]
Normal default easing, this is Quintic.easeOut.
| LinearGo | ||
|
pause():Boolean
Pauses play (including delay) for this LinearGo instance.
| LinearGo | ||
|
removeCallback(closure:Function, type:String):void
Removes a method closure previously stored using addCallback.
| LinearGo | ||
|
resume():Boolean
Resumes previously paused play, including delay.
| LinearGo | ||
|
setupUseFramesMode(defaultToFramesMode:Boolean = true, useZeroBasedFrameIndex:Boolean = false):void
[static]
A quick one-time setup command that lets you turn on useFrames mode
as a default for all new tweens and adjust some related settings.
| LinearGo | ||
|
skipTo(time:Number):Boolean
Skips to a point in the tween's duration and plays, from any state.
| LinearGo | ||
|
start():Boolean
Starts play for this LinearGo instance using GoEngine.
| LinearGo | ||
|
stop():Boolean
Ends play for this LinearGo instance and dispatches a GoEvent.STOP
event if the tween is incomplete.
| LinearGo | ||
![]() |
toString():String
Appends the regular toString value with the instance's playableID.
| PlayableBase | |
|
update(currentTime:Number):void
Performs tween calculations on GoEngine pulse.
| LinearGo | ||
| Method | Defined by | ||
|---|---|---|---|
|
onUpdate(type:String):void
Subclass this method (instead of the update method) for simplicity.
| LinearGo | ||
| Event | Summary | Defined by | ||
|---|---|---|---|---|
| Dispatched on an animation's final update, just after the last update event. | LinearGo | |||
| Dispatched at the end of each cycle if the tween has more than one. | LinearGo | |||
| Dispatched when pause() is called successfully. | LinearGo | |||
| Dispatched when resume() is called successfully. | LinearGo | |||
| Dispatched during an animation's first update after the delay has completed, if one was set. | LinearGo | |||
| Dispatched if an animation is manually stopped. | LinearGo | |||
| Dispatched on the animation's update pulse. | LinearGo | |||
| currentFrame | property |
currentFrame:uint [read-only]Returns the number of updates that have occured since start.
This update-count property does not necessarily correspond to the actual player framerate, just the instance's pulseInterval.
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 currentFrame property works. Its first value is 1 by
default, which can be changed to 0 in setupUseFramesMode().
This differs significantly from timePosition, 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.
public function get currentFrame():uint
See also
| defaultDelay | property |
public static var defaultDelay:Number = 0Class default for the instance property delay.
The default value is 0.
See also
| defaultDuration | property |
public static var defaultDuration:Number = 1Class default for the instance property duration.
The default value is 1.
See also
| defaultEasing | property |
public static var defaultEasing:FunctionClass default for the instance property easing. Note that this property is left null until the first LinearGo is instantiated, at which time it is set to Quintic.easeOut.
The default value is fl.motion.easing.Quintic.easeOut.
See also
| delay | property |
delay:Number [read-write]Number of seconds after start() call that the LinearGo begins processing.
If not set manually, the class default defaultDelay is adopted.
Implementation public function get delay():Number
public function set delay(value:Number):void
See also
| duration | property |
duration:Number [read-write]Number of seconds the LinearGo takes to process.
If not set manually, the class default defaultDuration is adopted.
Implementation public function get duration():Number
public function set duration(value:Number):void
See also
| easing | property |
easing:Function [read-write]Any standard easing-equation function such as the ones found in the Flash package fl.motion.easing or the flex package mx.effects.easing.
If not set manually, the class default defaultEasing is adopted. An error
is thrown if the function does not follow the typical format. For easings
that accept more than four parameters use extraEasingParams.
public function get easing():Function
public function set easing(value:Function):void
See also
| extraEasingParams | property |
extraEasingParams:Array [read-write]Additional parameters to pass to easing functions that accept more than four.
Implementation public function get extraEasingParams():Array
public function set extraEasingParams(value:Array):void
See also
| position | property |
position:Number [read-only]A number between 0 and 1 representing the current tween value.
Use this number as a multiplier to apply values to targets across time.
Here's an example of what an overridden update method might contain:
super.update(currentTime); target[ propName ] = super.correctValue(startValue + changeposition);Implementation
public function get position():Number
See also
| repeater | property |
repeater:LinearGoRepeater [read-only]A LinearGoRepeater instance that defines options for repeated or back-and-forth cycling animation.
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
linearGo.repeater.currentCycle. LinearGoRepeater's
reverseOnCycle 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 reverseOnCycle is disabled,
the animation will repeat its play forward each time.
(The repeater property replaces the cycles, easeOnCycle and currentCycle parameters in earlier releases of LinearGo).
Implementation public function get repeater():LinearGoRepeater
See also
| timePosition | property |
timePosition:Number [read-only]For time-based tweens, returns a time value which is negative during delay then spans the tween duration in positive values, ignoring repeat cycles.
In useFrames mode, this getter differs from currentFrame
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.
public function get timePosition():Number
See also
| useFrames | property |
useFrames:Boolean [read-write]Implementation
public function get useFrames():Boolean
public function set useFrames(value:Boolean):void
| LinearGo | () | constructor |
public function LinearGo(delay:Number, duration:Number, easing:Function = null, extraEasingParams:Array = null, repeater:LinearGoRepeater = null, useRelative:Boolean = false, useRounding:Boolean = false, useFrames:Boolean = false, pulseInterval:Number)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.
Parametersdelay:Number |
|
duration:Number |
|
easing:Function (default = null) |
|
extraEasingParams:Array (default = null) |
|
repeater:LinearGoRepeater (default = null) |
|
useRelative:Boolean (default = false) |
|
useRounding:Boolean (default = false) |
|
useFrames:Boolean (default = false) |
|
pulseInterval:Number |
| addCallback | () | method |
public function addCallback(closure:Function, type:String):voidAn 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).
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.
Parametersclosure:Function — A reference to a callback function
|
|
type:String — Any GoEvent type constant, the default is COMPLETE.
|
See also
| easeNone | () | method |
public static function easeNone(t:Number, b:Number, c:Number, d:Number):NumberAn alternative default easing with no acceleration. (The two default easings in this class are included because there's currently no single easing classpath shared between Flash & Flex.)
Parameterst:Number |
|
b:Number |
|
c:Number |
|
d:Number |
Number |
| easeOut | () | method |
public static function easeOut(t:Number, b:Number, c:Number, d:Number):NumberNormal default easing, this is Quintic.easeOut. (The two default easings in this class are included because there's currently no single easing classpath shared between Flash & Flex.)
Parameterst:Number |
|
b:Number |
|
c:Number |
|
d:Number |
Number |
| onUpdate | () | method |
protected function onUpdate(type:String):voidSubclass this method (instead of the update method) for simplicity.
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.
CONVENTION ALERT: To implement the Go convention useRounding,
always call GoItem's correctValue() method on each calculated
tween value before you apply it to a target. This corrects NaN to 0 and
rounds the value if useRounding is true.
override protected function onUpdate(type:String):void
{
target[ propName ] = super.correctValue(startValue + changeposition);
}
Parameters
type:String — A constant from the class GoEvent: START, UPDATE, CYCLE, or COMPLETE.
|
See also
| pause | () | method |
public function pause():BooleanPauses play (including delay) for this LinearGo instance. This method does not typically require subclassing.
ReturnsBoolean — Success
|
See also
| removeCallback | () | method |
public function removeCallback(closure:Function, type:String):voidRemoves a method closure previously stored using addCallback.
Parametersclosure:Function — A reference to a function
|
|
type:String — A GoEvent constant, default is COMPLETE.
|
See also
| resume | () | method |
public function resume():BooleanResumes previously paused play, including delay. This method does not typically require subclassing.
ReturnsBoolean — Success
|
See also
| setupUseFramesMode | () | method |
public static function setupUseFramesMode(defaultToFramesMode:Boolean = true, useZeroBasedFrameIndex:Boolean = false):voidA quick one-time setup command that lets you turn on useFrames mode as a default for all new tweens and adjust some related settings. (Note that useFrames mode is normally only used for specialty situations.)
ParametersdefaultToFramesMode:Boolean (default = true) — Sets an internal default so all new LinearGo instances
will be set to use framecounts for their delay and duration.
Also sets GoItem.defaultPulseInterval to enterframe which is
most normal for frame-based updates.
|
|
useZeroBasedFrameIndex:Boolean (default = false) — Normally currentFrame reads 1 on first update, like the Flash
timeline starts at Frame 1. Set this option to use a zero-based
index on all tweens instead.
|
See also
| skipTo | () | method |
public function skipTo(time:Number):BooleanSkips to a point in the tween's duration and plays, from any state. This method does not typically require subclassing.
If GoItem.timeMultiplier is set to a custom value, you should still pass a seconds value based on the tween's real duration setting.
Parameterstime:Number — 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.
|
Boolean — Success
|
See also
| start | () | method |
public function start():BooleanStarts play for this LinearGo instance using GoEngine.
CONVENTION ALERT: If useRelative is true, calculate tween values
relative to the target object's existing value as in the example below.
Most typically you should also store the tween's start and change values
for later use in onUpdate.
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());
}
Returns
Boolean — Successful addition of the item to GoEngine
|
See also
| stop | () | method |
public function stop():BooleanEnds play for this LinearGo instance and dispatches a GoEvent.STOP event if the tween is incomplete. This method does not typically require subclassing.
ReturnsBoolean — Successful removal of the item from GoEngine
|
| update | () | method |
public override function update(currentTime:Number):voidPerforms tween calculations on GoEngine pulse.
Subclass onUpdate instead of this method.
Parameters
currentTime:Number — Clock time for the current block of updates.
|
See also
| COMPLETE | event |
org.goasap.events.GoEvent
Dispatched on an animation's final update, just after the last update event.
Any number of callbacks may also be associated with this event using
addCallback.
| CYCLE | event |
org.goasap.events.GoEvent
Dispatched at the end of each cycle if the tween has more than one.
Any number of callbacks may also be associated with this event using
addCallback.
| PAUSE | event |
org.goasap.events.GoEvent
Dispatched when pause() is called successfully. Any number of callbacks
may also be associated with this event using addCallback.
| RESUME | event |
org.goasap.events.GoEvent
Dispatched when resume() is called successfully. Any number of callbacks
may also be associated with this event using addCallback.
| START | event |
org.goasap.events.GoEvent
Dispatched during an animation's first update after the delay
has completed, if one was set. Any number of callbacks may also be
associated with this event using addCallback.
| STOP | event |
org.goasap.events.GoEvent
Dispatched if an animation is manually stopped. Any number of callbacks
may also be associated with this event using addCallback.
| UPDATE | event |
org.goasap.events.GoEvent
Dispatched on the animation's update pulse. Any number of callbacks
may also be associated with this event using addCallback.