GTweenTimeline is a powerful sequencing engine for GTween. It allows you to build a virtual timeline with tweens, actions (callbacks), and labels. It supports all of the features of GTween, so you can repeat, reflect, and pause the timeline. You can even embed timelines within each other. GTweenTimeline adds about 1.2kb above GTween.
Static methods
staticsetPropertyValue(target:Any, propertyName:String, value:Any):Void
Sets a property value on a specified target object. This is provided to make it easy to set properties
in a GTweenTimeline using addCallback
. For example, to set the visible
property to true on a movieclip "foo"
at 3 seconds into the timeline, you could use the following code:
myTimeline.addCallback(3,GTweenTimeline.setPropertyValue,[foo,"visible",true]);
Parameters:
target | The object to set the property value on. |
---|---|
propertyName | The name of the property to set. |
value | The value to assign to the property. |
Constructor
new(?target:Any, duration:Float = 1, ?values:Any, ?props:Any, ?pluginData:Any, ?tweens:Array<Any>)
Constructs a new GTweenTimeline instance. Note that because GTweenTimeline extends GTween, it can be used to tween a target directly, in addition to using its timeline features (for example, to synch tweening an animation with a timeline sequence).
Parameters:
target | The object whose properties will be tweened. Defaults to null. |
---|---|
duration | The length of the tween in frames or seconds depending on the timingMode. Defaults to 10. |
values | An object containing destination property values. For example, to tween to x=100, y=100, you could pass |
props | An object containing properties to set on this tween. For example, you could pass {ease:myEase} to set the ease property of the new instance. It also supports a single special property "swapValues" that will cause |
pluginData | An object containing data for installed plugins to use with this tween. See |
tweens | An array of alternating start positions and tween instances. For example, the following array would add 3 tweens starting at positions 2, 6, and 8: |
Variables
suppressCallbacks:Bool = false
If true, callbacks added with addCallback will not be called. This does not
affect event callbacks like onChange, which can be disabled with suppressEvents.
This can be handy for preventing large numbers of callbacks from being called when
manually changing the position of a timeline (ex. calling .end()
).
Methods
addCallback(labelOrPosition:Any, forwardCallback:Function, ?forwardParameters:Array<Any>, ?reverseCallback:Function, ?reverseParameters:Array<Any>):Void
Adds a callback function at the specified position. When the timeline's playhead passes over or lands on the position while playing the callback will be called with the parameters specified. You can also optionally specify a callback and parameters to use if the timeline is playing in reverse (when reflected for example).
You can add multiple callbacks at a specified position, however it is important to note that they will be played in the same order (most recently added first) playing both forwards and in reverse. You can enforce the order they are called in by offsetting the callbacks' positions by a tiny amount (ex. one at 2s, and one at 2.001s).
Note that this can be used in conjunction with the static setPropertyValue
method to easily set properties on objects in the timeline.
Parameters:
labelOrPosition | The position or label to add the callback at in frames or seconds (as per the timing mode of this tween). |
---|---|
forwardCallback | The function to call when playing forwards. |
forwardParameters | Optional array of parameters to pass to the callback when it is called when playing forwards. |
reverseCallback | The function to call when playing in reverse. |
reverseParameters | Optional array of parameters to pass to the callback when it is called when playing in reverse. |
addLabel(position:Float, label:String):Void
Adds a label at the specified position. You can use gotoAndPlay
or gotoAndStop
to jump to labels.
Parameters:
position | The position to add the label at in frames or seconds (as per the timing mode of this tween). |
---|---|
label | The label to add. |
addTween(position:Float, tween:GTween):Void
Adds a tween to the timeline, which will start playing at the specified start position.
The tween will play synchronized with the timeline, with all of its behaviours intact (ex. repeat
, reflect
)
except for delay
(which is accomplished with the position
parameter instead).
Parameters:
position | The starting position for this tween in frames or seconds (as per the timing mode of this tween). |
---|---|
tween | The GTween instance to add. Note that this can be any subclass of GTween, including another GTweenTimeline. |
addTweens(tweens:Array<Any>):Void
Shortcut method for adding a number of tweens at once.
Parameters:
tweens | An array of alternating positions and tween instances. For example, the following array would add 3 tweens starting at positions 2, 6, and 8: |
---|
calculateDuration():Void
Calculates and sets the duration of the timeline based on the tweens and callbacks that have been added to it.
goto(labelOrPosition:Any):Void
Jumps the timeline to the specified label or numeric position without affecting its paused state.
Parameters:
labelOrPosition | The label name or numeric position in frames or seconds (as per the timing mode of this tween) to jump to. |
---|
gotoAndPlay(labelOrPosition:Any):Void
Jumps the timeline to the specified label or numeric position and plays it.
Parameters:
labelOrPosition | The label name or numeric position in frames or seconds (as per the timing mode of this tween) to jump to. |
---|
gotoAndStop(labelOrPosition:Any):Void
Jumps the timeline to the specified label or numeric position and pauses it.
Parameters:
labelOrPosition | The label name or numeric position in frames or seconds (as per the timing mode of this tween) to jump to. |
---|
removeCallback(labelOrPosition:Any):Void
Removes the callback(s) at the specified label or position.
Parameters:
labelOrPosition | The position of the callback(s) to remove in frames or seconds (as per the timing mode of this tween). |
---|
removeTween(tween:GTween):Void
Removes the specified tween. Note that this will remove all instances of the tween if has been added multiple times to the timeline.
Parameters:
tween | The GTween instance to remove. |
---|
resolveLabelOrPosition(labelOrPosition:Any):Float
Returns the position for the specified label. If a numeric position is specified, it is returned unchanged.
Parameters:
labelOrPosition | The label name or numeric position in frames or seconds (as per the timing mode of this tween) to resolve. |
---|