Package | com.greensock |
Class | public class TweenLite |
Inheritance | TweenLite Animation Object |
Subclasses | TweenMax |
pause()/resume()
anytime, and intelligently manage conflicting tweens of
the same object with various overwrite modes. TweenMax extends TweenLite and adds even
more capabilities like repeat, yoyo, repeatDelay, on-the-fly destination value
updates and more.time
or progress
to fastforward or rewind the entire timeline. Add
labels, change the timeline's timeScale, nest timelines within timelines, and much more.
This can revolutionize your animation workflow, making it more modular and concise.USAGE
To get up and running quickly, check out the Jump Start tour which covers the basics in a fun, interactive way.
The most common type of tween is a to() tween which allows you to define the destination values:
TweenLite.to(document.getElementById("photo"), 2, {width:200, height:150});
The above code will tween the width and height properties of the <img> DOM element with
an id of "photo" from whatever the current values are to 200 and 150 respectively over the course
of 2 seconds. Notice the width and height values are defined inside a generic object (between curly braces).
Put as many properties there as you want. Also note that <img> elements are one of the few DOM
elements that have width
and height
properties whereas most others
(like <div> elements) require css properties to be applied in order to control their width/height
(among other properties). To animate those css properties, you'll need to use the CSSPlugin. The CSSPlugin
contains special code for deciphering css-related properties and handling them in unique ways,
like recognizing colors, transforms, etc. and managing the necessary suffixes ("px", "%", etc.).
Once you load the CSSPlugin JavaScript file, you can animate css-related properties by wrapping
them in a generic object that you name "css" like this:
TweenLite.to(document.getElementById("div1"), 2, {css:{backgroundColor:"#ff0000", width:"50%", top:"100px"}, ease:Power2.easeInOut});
Just tuck all the css-related properties inside the "css" object. The other special properties
like ease, delay, onComplete,
etc. stay outside the css object (we'll discuss special
properties later).
By default, tweens begin immediately, although you can delay them using the delay
special property or pause them initially using the paused
special property (see below).
The target
can also be an array of objects. For example, the following tween will
tween the opacity
css property to 0.5 and the rotation transform property to 45 for
obj1, obj2, and obj3:
TweenLite.to([obj1, obj2, obj3], 1, {css:{opacity:0.5, rotation:45}});
You can also use a from() tween if you want to define the starting values instead of the ending values so that the target tweens from the defined values to wherever they currently are. Or a fromTo() lets you define both starting and ending values.
Although the to()
, from()
, and fromTo()
static methods
are popular because they're quick and can avoid some garbage collection hassles, you can also
use the more object-oriented syntax like this:
var tween = new TweenLite(myObject, 2, {width:200, height:150});
or even:
var tween = TweenLite.to(myObject, 2, {width:200, height:150});
SPECIAL PROPERTIES (no plugins required):
Typically the vars
parameter is used to define ending values for tweening
properties of the target
(or beginning values for from()
tweens)
like {x:100, y:200, alpha:0}
, but the following optional special properties
serve other purposes:
ElasticOut.ease
or StrongInOut.ease
. For best performance, use one of the GreenSock eases
(which are in the com.greensock.easing
package). TweenLite also works with
any standard easing equation that uses the typical 4 parameters (time, start,
change, duration
) like Adobe's fl.motion.easing
eases.
The default is Power1.easeOut
. For linear animation, use the GreenSock
Linear.ease
easeonComplete
function. For example,
TweenLite.to(mc, 1, {x:100, onComplete:myFunction, onCompleteParams:[mc, "param2"]});
To self-reference the tween instance itself in one of the parameters, use "{self}"
,
like: onCompleteParams:["{self}", "param2"]
"this"
refers to inside that function).useFrames
is true
, the tweens's timing will be
based on frames instead of seconds because it is intially added to the root
frames-based timeline. This causes both its duration
and delay
to be based on frames. An animations's timing mode is
always determined by its parent timeline
.delay
. However, if you prefer to force the tween to
render immediately when it is created, set immediateRender
to true
.
Or to prevent a from()
from rendering immediately, set immediateRender
to false
. By default, from()
tweens set immediateRender
to true
.time
changes from 0 to some other value which can happen more than once if the
tween is restarted multiple times).onStart
function. For example,
TweenLite.to(mc, 1, {x:100, delay:1, onStart:myFunction, onStartParams:[mc, "param2"]});
To self-reference the tween instance itself in one of the parameters, use "{self}"
,
like: onStartParams:["{self}", "param2"]
"this"
refers to inside that function).onUpdate
function. For example,
TweenLite.to(mc, 1, {x:100, onUpdate:myFunction, onUpdateParams:[mc, "param2"]});
To self-reference the tween instance itself in one of the parameters, use "{self}"
,
like: onUpdateParams:["{self}", "param2"]
"this"
refers to inside that function).reverse()
is called the tween will move
back towards its beginning and when its time
reaches 0, onReverseComplete
will be called. This can also happen if the tween is placed in a TimelineLite or TimelineMax instance
that gets reversed and plays the tween backwards to (or past) the beginning.onReverseComplete
function. For example,
TweenLite.to(mc, 1, {x:100, onReverseComplete:myFunction, onReverseCompleteParams:[mc, "param2"]});
To self-reference the tween instance itself in one of the parameters, use "{self}"
,
like: onReverseCompleteParams:["{self}", "param2"]
"this"
refers to inside that function).true
, the tween will pause itself immediately upon creation."auto"
is the default (although
you can change the default mode using the TweenLite.defaultOverwrite
property):
"none"
(0) (or false
) - no overwriting will occur."all"
(1) (or true
) - immediately overwrites all existing
tweens of the same target even if they haven't started yet or don't have
conflicting properties."auto"
(2) - when the tween renders for the first time, it will analyze
tweens of the same target that are currently active/running and only overwrite
individual tweening properties that overlap/conflict. Tweens that haven't begun
yet are ignored. For example, if another active tween is found that is tweening
3 properties, only 1 of which it shares in common with the new tween, the other
2 properties will be left alone. Only the conflicting property gets overwritten/killed.
This is the default mode and typically the most intuitive for developers."concurrent"
(3) - when the tween renders for the first time, it kills
only the active (in-progress) tweens of the same target regardless of whether
or not they contain conflicting properties. Like a mix of "all"
and "auto"
. Good for situations where you only want one tween
controling the target at a time."allOnStart"
(4) - Identical to "all"
but waits to run
the overwrite logic until the tween begins (after any delay). Kills
tweens of the same target even if they don't contain conflicting properties
or haven't started yet."preexisting"
(5) - when the tween renders for the first time, it kills
only the tweens of the same target that existed BEFORE this tween was created
regardless of their scheduled start times. So, for example, if you create a tween
with a delay of 10 and then a tween with a delay of 1 and then a tween with a
delay of 2 (all of the same target), the 2nd tween would overwrite the first
but not the second even though scheduling might seem to dictate otherwise.
"preexisting"
only cares about the order in which the instances
were actually created. This can be useful when the order in which your code runs
plays a critical role.PLUGINS:
Think of plugins like special properties that are dynamically added, delivering extra abilities without forcing them to be baked into the core engine, keeping it relatively lean and mean. Each plugin is associated with a property name and it takes responsibility for handling that property. For example, the CSSPlugin is associated with the "css" property name so if it is activated it will intercept the "css" property in the following tween and manage it in a special way so that the tweens affect the element's style object (for manipulating DOM elements):
TweenLite.to(element, 1, {css:{top:"100px", left:"50px", backgroundColor:"#ff0000", fontSize:"12px"}, delay:0.5});
If the CSSPlugin wasn't activated (loaded), TweenLite would act as though you were trying to literally tween the
element.css
property (and there is no such thing).
In the JavaScript version of TweenLite, activating a plugin is as simple as loading the associated .js file.
No extra activation code is necessary. In the ActionScript version, activating a plugin requires a single line
of code and you only need to do it once, so it's pretty easy. Simply pass an Array containing the names of all
the plugins you'd like to activate to the TweenPlugin.activate()
method, like this:
TweenPlugin.activate([FrameLabelPlugin, ColorTransformPlugin, TintPlugin]);
To make it even easier, there is a Plugin Explorer which writes the code for you. All you need to do is select the plugins and copy/paste the code from the bottom of the tool. It also displays interactive examples of each plugin and the assocaited code so that it’s easy to see the correct syntax.
EXAMPLES:
Please see http://www.greensock.com for examples, tutorials, and interactive demos.
NOTES / TIPS:TweenLite.to(mc, 2, {x:"-=20"});
it'll
tween mc.x
to the left 20 pixels. {x:"+=20"}
would move it to the right.TweenLite.defaultEase
if you prefer something other
than Power1.easeOut
.TweenLite.killTweensOf(myObject);
TweenLite.killDelayedCallsTo(myFunction);
or TweenLite.killTweensOf(myFunction);
TweenLite.from()
method to animate things into place. For example,
if you have things set up on the stage in the spot where they should end up, and you
just want to animate them into place, you can pass in the beginning x and/or y and/or
alpha (or whatever properties you want).Copyright 2006-2012, GreenSock. All rights reserved. This work is subject to the terms in http://www.greensock.com/terms_of_use.html or for Club GreenSock members, the software agreement that was issued with the membership.
Property | Defined By | ||
---|---|---|---|
data : * A place to store any data you want (initially populated with vars.data if it exists). | Animation | ||
defaultEase : Ease [static] Provides An easy way to change the default easing equation. | TweenLite | ||
defaultOverwrite : String = auto [static] Provides An easy way to change the default overwrite mode. | TweenLite | ||
target : Object [READ-ONLY] Target object (or array of objects) whose properties the tween affects. | TweenLite | ||
ticker : Object [static]
The object that dispatches a "tick" event each time the engine updates, making it easy for
you to add your own listener(s) to run custom logic after each update (great for game developers). | TweenLite | ||
timeline : SimpleTimeline [Read-only] Parent timeline. | Animation | ||
vars : Object The vars object passed into the constructor which stores configuration variables like onComplete, onUpdate, etc. | Animation |
Method | Defined By | ||
---|---|---|---|
TweenLite(target:Object, duration:Number, vars:Object)
Constructor
| TweenLite | ||
delay(value:Number):*
Gets or sets the animation's initial delay which is the length of time in seconds
(or frames for frames-based tweens) before the animation should begin. | Animation | ||
delayedCall(delay:Number, callback:Function, params:Array = null, scope:* = null, useFrames:Boolean = false):TweenLite [static]
Provides a simple way to call a function after a set amount of time (or frames). | TweenLite | ||
duration(value:Number):*
Gets or sets the animation's duration, not including any repeats or repeatDelays
(which are only available in TweenMax and TimelineMax). | Animation | ||
eventCallback(type:String, callback:Function = null, params:Array = null, scope:* = null):*
Gets or sets an event callback like "onComplete", "onUpdate", "onStart", "onReverseComplete"
or "onRepeat" (onRepeat only applies to TweenMax or TimelineMax instances)
along with any parameters that should be passed to that callback. | Animation | ||
[static]
Static method for creating a TweenLite instance that tweens backwards -
you define the BEGINNING values and the current values are used
as the destination values which is great for doing things like animating objects
onto the screen because you can set them up initially the way you want them to look
at the end of the tween and then animate in from elsewhere. | TweenLite | ||
[static]
Static method for creating a TweenLite instance that allows you to define both the starting
and ending values (as opposed to to() and from() tweens which are
based on the target's current values at one end or the other). | TweenLite | ||
getTweensOf(target:*):Array [static]
Returns an array containing all the tweens of a particular target (or group of targets) that have not
been released for garbage collection yet which typically happens within a few seconds after the tween completes. | TweenLite | ||
invalidate():* [override]
Clears any initialization data (like starting/ending values in tweens) which can be useful if, for example,
you want to restart a tween without reverting to any previously recorded starting values. | TweenLite | ||
kill(vars:Object = null, target:Object = null):*
Kills the animation entirely or in part depending on the parameters. | Animation | ||
killDelayedCallsTo(func:Function):void [static]
Immediately kills all of the delayedCalls to a particular function. | TweenLite | ||
killTweensOf(target:*, vars:Object = null):void [static]
Kills all the tweens (or specific tweening properties) of a particular object or delayedCalls
to a particular function. | TweenLite | ||
pause(atTime:* = null, suppressEvents:Boolean = true):*
Pauses the instance, optionally jumping to a specific time. | Animation | ||
paused(value:Boolean = false):*
Gets or sets the animation's paused state which indicates whether or not the animation
is currently paused. | Animation | ||
play(from:* = null, suppressEvents:Boolean = true):*
Begins playing forward, optionally from a specific time (by default playback begins from
wherever the playhead currently is). | Animation | ||
restart(includeDelay:Boolean = false, suppressEvents:Boolean = true):*
Restarts and begins playing forward from the beginning. | Animation | ||
resume(from:* = null, suppressEvents:Boolean = true):*
Resumes playing without altering direction (forward or reversed), optionally jumping to a specific time first. | Animation | ||
reverse(from:* = null, suppressEvents:Boolean = true):*
Reverses playback so that all aspects of the animation are oriented backwards including, for example,
a tween's ease. | Animation | ||
reversed(value:Boolean = false):*
Gets or sets the animation's reversed state which indicates whether or not the animation
should be played backwards. | Animation | ||
seek(time:*, suppressEvents:Boolean = true):*
Jumps to a specific time without affecting whether or not the instance is paused or reversed. | Animation | ||
[static]
Immediately sets properties of the target accordingly - essentially a zero-duration to() tween with a more
intuitive name. | TweenLite | ||
startTime(value:Number):*
Gets or sets the time at which the animation begins on its parent timeline (after any delay
that was defined). | Animation | ||
time(value:Number, suppressEvents:Boolean = false):*
Gets or sets the local position of the playhead (essentially the current time),
described in seconds (or frames for frames-based animations) which
will never be less than 0 or greater than the animation's duration. | Animation | ||
timeScale(value:Number):*
Factor that's used to scale time in the animation where 1 = normal speed (the default),
0.5 = half speed, 2 = double speed, etc. | Animation | ||
[static]
Static method for creating a TweenLite instance that animates to the specified destination values
(from the current values). | TweenLite | ||
totalDuration(value:Number):*
Gets or sets the animation's total duration including
any repeats or repeatDelays (which are only available in TweenMax and TimelineMax). | Animation | ||
totalTime(time:Number, suppressEvents:Boolean = false):*
Gets or sets the position of the playhead according to the totalDuration
which includes any repeats and repeatDelays (only available
in TweenMax and TimelineMax). | Animation |
defaultEase | property |
public static var defaultEase:Ease
Provides An easy way to change the default easing equation. Choose from any of the GreenSock eases in the com.greensock.easing
package.
The default value is Power1.easeOut
.
defaultOverwrite | property |
public static var defaultOverwrite:String = auto
Provides An easy way to change the default overwrite mode. Choose from any of the following: "auto", "all", "none", "allOnStart", "concurrent", "preexisting"
.
The default value is "auto"
.
target | property |
public var target:Object
[READ-ONLY] Target object (or array of objects) whose properties the tween affects.
ticker | property |
public static var ticker:Object
The object that dispatches a "tick"
event each time the engine updates, making it easy for
you to add your own listener(s) to run custom logic after each update (great for game developers).
Add as many listeners as you want. The basic syntax is the same for all versions (AS2, AS3, and JavaScript):
Basic example (AS2, AS3, and JavaScript):
//add listener TweenLite.ticker.addEventListener("tick", myFunction); function myFunction(event) { //executes on every tick after the core engine updates } //to remove the listener later... TweenLite.ticker.removeEventListener("tick", myFunction);
Due to differences in the core languages (and to maximize efficiency), the advanced syntax is slightly different for the AS3 version compared to AS2 and JavaScript. The parameters beyond the first 2 in the addEventListener() method are outlined below:
JavaScript and AS2
addEventListener(type, callback, scope, useParam, priority)
Parameters:
"tick"
this
" refers to in your function). This can be very useful in JavaScript and AS2 because scope isn't generally maintained. true
, an event object will be generated and fed to the callback each time the event occurs. The event is a generic object and has two properties: type
(always "tick"
) and target
which refers to the ticker instance. The default for useParam
is false
because it improves performance.Advanced example (JavaScript and AS2):
//add listener that requests an event object parameter, binds scope to the current scope (this), and sets priority to 1 so that it is called before any other listeners that had a priority lower than 1... TweenLite.ticker.addEventListener("tick", myFunction, this, true, 1); function myFunction(event) { //executes on every tick after the core engine updates } //to remove the listener later... TweenLite.ticker.removeEventListener("tick", myFunction);
AS3
The AS3 version uses the standard EventDispatcher.addEventListener()
syntax which
basically allows you to define a priority and whether or not to use weak references (see Adobe's
docs for details).
Advanced example [AS3 only]:
import flash.events.Event; //add listener with weak reference (standard syntax - notice the 5th parameter is true) TweenLite.ticker.addEventListener("tick", myFunction, false, 0, true); function myFunction(event:Event):void { //executes on every tick after the core engine updates } //to remove the listener later... TweenLite.ticker.removeEventListener("tick", myFunction);
TweenLite | () | Constructor |
public function TweenLite(target:Object, duration:Number, vars:Object)
Constructor
Parameterstarget:Object — Target object (or array of objects) whose properties this tween affects
| |
duration:Number — Duration in seconds (or frames if useFrames:true is set in the vars parameter)
| |
vars:Object — An object defining the end value for each property that should be tweened as well as any special properties like onComplete , ease , etc. For example, to tween mc.x to 100 and mc.y to 200 and then call myFunction , do this: new TweenLite(mc, 1, {x:100, y:200, onComplete:myFunction}) .
|
delayedCall | () | method |
public static function delayedCall(delay:Number, callback:Function, params:Array = null, scope:* = null, useFrames:Boolean = false):TweenLite
Provides a simple way to call a function after a set amount of time (or frames). You can optionally pass any number of parameters to the function too.
JavaScript and AS2 note: - Due to the way JavaScript and AS2 don't
maintain scope (what "this
" refers to, or the context) in function calls,
it can be useful to define the scope specifically. Therefore, the JavaScript and AS2
versions accept a 4th parameter to [optionally] define the scope
, but it
is omitted in AS3:
TweenLite.delayedCall(delay, callback, params, scope, useFrames)
[JavaScript and AS2 only]
//calls myFunction after 1 second and passes 2 parameters: TweenLite.delayedCall(1, myFunction, ["param1", 2]); function myFunction(param1, param2) { //do stuff }
Parameters
delay:Number — Delay in seconds (or frames if useFrames is true ) before the function should be called
| |
callback:Function — Function to call
| |
params:Array (default = null ) — An Array of parameters to pass the function (optional).
| |
scope:* (default = null ) — The scope in which the callback should be called (basically, what "this" refers to in the function). NOTE: this parameter only exists in the JavaScript and AS2 versions.
| |
useFrames:Boolean (default = false ) — If the delay should be measured in frames instead of seconds, set useFrames to true (default is false )
|
TweenLite — TweenLite instance
|
See also
from | () | method |
public static function from(target:Object, duration:Number, vars:Object):TweenLite
Static method for creating a TweenLite instance that tweens backwards - you define the BEGINNING values and the current values are used as the destination values which is great for doing things like animating objects onto the screen because you can set them up initially the way you want them to look at the end of the tween and then animate in from elsewhere.
NOTE: By default, immediateRender
is true
in
from()
tweens, meaning that they immediately render their starting state
regardless of any delay that is specified. You can override this behavior by passing
immediateRender:false
in the vars
parameter so that it will
wait to render until the tween actually begins (often the desired behavior when inserting
into TimelineLite or TimelineMax instances). To illustrate the default behavior, the
following code will immediately set the alpha
of mc
to 0 and then wait 2 seconds before tweening the alpha
back to 1 over
the course of 1.5 seconds:
TweenLite.from(mc, 1.5, {alpha:0, delay:2});
Since the target
parameter can also be an array of objects, the following
code will tween the alpha property of mc1, mc2, and mc3 from a value of 0 simultaneously:
TweenLite.from([mc1, mc2, mc3], 1.5, {alpha:0});
Even though 3 objects are animating, there is still only one tween created.
In order to stagger or offset the start times of each object animating, please see
the staggerFrom()
method of TimelineLite or TweenMax.
For simple sequencing, you can use the delay
special property
(like TweenLite.from(mc, 1, {alpha:0, delay:0.5})
),
but it is highly recommended that you consider using TimelineLite (or TimelineMax)
for all but the simplest sequencing tasks. It has an identical from()
method
that allows you to append tweens one-after-the-other and then control the entire sequence
as a whole. You can even have the tweens overlap as much as you want.
Parameters
target:Object — Target object (or array of objects) whose properties this tween affects.
| |
duration:Number — Duration in seconds (or frames if useFrames:true is set in the vars parameter)
| |
vars:Object — An object defining the starting value for each property that should be tweened as well as any special properties like onComplete , ease , etc. For example, to tween mc.x from 100 and mc.y from 200 and then call myFunction , do this: TweenLite.from(mc, 1, {x:100, y:200, onComplete:myFunction});
|
TweenLite — TweenLite instance
|
See also
fromTo | () | method |
public static function fromTo(target:Object, duration:Number, fromVars:Object, toVars:Object):TweenLite
Static method for creating a TweenLite instance that allows you to define both the starting
and ending values (as opposed to to()
and from()
tweens which are
based on the target's current values at one end or the other).
NOTE: Only put starting values in the fromVars
parameter - all
special properties for the tween (like onComplete, onUpdate, delay, etc.) belong in the toVars
parameter.
Since the target
parameter can also be an array of objects, the following
code will tween the x property of mc1, mc2, and mc3 from 0 to 100 simultaneously:
TweenLite.fromTo([mc1, mc2, mc3], 1, {x:0}, {x:100});
Even though 3 objects are animating, there is still only one tween created.
In order to stagger or offset the start times of each object animating, please see
the staggerFromTo()
method of TimelineLite or TweenMax.
For simple sequencing, you can use the delay
special property
(like TweenLite.fromTo(mc, 1, {x:0}, {x:100, delay:0.5})
),
but it is highly recommended that you consider using TimelineLite (or TimelineMax)
for all but the simplest sequencing tasks. It has an identical fromTo()
method
that allows you to append tweens one-after-the-other and then control the entire sequence
as a whole. You can even have the tweens overlap as much as you want.
Parameters
target:Object — Target object (or array of objects) whose properties this tween affects.
| |
duration:Number — Duration in seconds (or frames if useFrames:true is set in the vars parameter)
| |
fromVars:Object — An object defining the starting value for each property that should be tweened. For example, to tween mc.x from 100 and mc.y from 200, fromVars would look like this: {x:100, y:200} .
| |
toVars:Object — An object defining the end value for each property that should be tweened as well as any special properties like onComplete , ease , etc. For example, to tween mc.x from 0 to 100 and mc.y from 0 to 200 and then call myFunction , do this: TweenLite.fromTo(mc, 1, {x:0, y:0}, {x:100, y:200, onComplete:myFunction});
|
TweenLite — TweenLite instance
|
See also
getTweensOf | () | method |
public static function getTweensOf(target:*):Array
Returns an array containing all the tweens of a particular target (or group of targets) that have not
been released for garbage collection yet which typically happens within a few seconds after the tween completes.
For example, TweenLite.getTweensOf(myObject)
returns an array of all tweens
of myObject
, even tweens that haven't begun yet. TweenLite.getTweensOf([myObject1, myObject2]);
will return a condensed array of the tweens of myObject1
plus all the tweens
of myObject2
combined into one array with duplicates removed.
Since the method only finds tweens that haven't been released for garbage collection, if you create a tween
and then let it finish and then a while later try to find it with getTweensOf()
, it may not be found
because it was released by the engine for garbage collection. Remember, one of the best parts of GSAP is that it
saves you from the headache of managing gc. Otherwise, you'd need to manually dispose each tween you create, making
things much more cumbersome.
TweenLite.to(myObject1, 1, {x:100}); TweenLite.to(myObject2, 1, {x:100}); TweenLite.to([myObject1, myObject2], 1, {alpha:0}); var a1 = TweenLite.getTweensOf(myObject1); //finds 2 tweens var a2 = TweenLite.getTweensOf([myObject1, myObject2]); //finds 3 tweens
Parameters
target:* — The target whose tweens should be returned, or an array of such targets
|
Array — An array of tweens
|
invalidate | () | method |
override public function invalidate():*
Clears any initialization data (like starting/ending values in tweens) which can be useful if, for example,
you want to restart a tween without reverting to any previously recorded starting values. When you invalidate()
an animation, it will be re-initialized the next time it renders and its vars
object will be re-parsed.
The timing of the animation (duration, startTime, delay) will not be affected.
Another example would be if you have a TweenMax(mc, 1, {x:100, y:100})
that ran when mc.x and mc.y
were initially at 0, but now mc.x and mc.y are 200 and you want them tween to 100 again, you could simply
invalidate()
the tween and restart()
it. Without invalidating first, restarting it
would cause the values jump back to 0 immediately (where they started when the tween originally began).
When you invalidate a TimelineLite/TimelineMax, it automatically invalidates all of its children.
* — self (makes chaining easier)
|
killDelayedCallsTo | () | method |
public static function killDelayedCallsTo(func:Function):void
Immediately kills all of the delayedCalls to a particular function. If, for example,
you want to kill all delayedCalls to myFunction
, you'd do this:
TweenLite.killDelayedCallsTo(myFunction);
Since a delayedCall is just a tween that uses the function/callback as both its target
and its onComplete
, TweenLite.killTweensOf(myFunction)
produces exactly the
same result as TweenLite.killDelayedCallsTo(myFunction)
.
This method affects all delayedCalls that were created using TweenLite.delayedCall()
or TweenMax.delayedCall()
or the call()
or addCallback()
methods
of TimelineLite or TimelineMax. Basically, any tween whose target is the function you supply will
be killed.
Parameters
func:Function — The function for which all delayedCalls should be killed/cancelled.
|
killTweensOf | () | method |
public static function killTweensOf(target:*, vars:Object = null):void
Kills all the tweens (or specific tweening properties) of a particular object or delayedCalls
to a particular function. If, for example, you want to kill all tweens of myObject
,
you'd do this:
TweenLite.killTweensOf(myObject);
To kill only particular tweening properties of the object, use the second parameter.
For example, if you only want to kill all the tweens of myObject.alpha
and
myObject.x
, you'd do this:
TweenLite.killTweensOf(myObject, {alpha:true, x:true});
To kill all the delayedCalls that were created like TweenLite.delayedCall(5, myFunction);
,
you can simply call TweenLite.killTweensOf(myFunction);
because delayedCalls
are simply tweens that have their target
and onComplete
set to
the same function (as well as a delay
of course).
killTweensOf()
affects tweens that haven't begun yet too. If, for example,
a tween of myObject
has a delay
of 5 seconds and
TweenLite.killTweensOf(mc)
is called 2 seconds after the tween was created,
it will still be killed even though it hasn't started yet.
Parameters
target:* — Object whose tweens should be killed immediately
| |
vars:Object (default = null ) — To kill only specific properties, use a generic object containing enumerable properties corresponding to the ones that should be killed like {x:true, y:true} . The values assigned to each property of the object don't matter - the sole purpose of the object is for iteration over the named properties (in this case, x and y ). If no object (or null ) is defined, all matched tweens will be killed in their entirety.
|
set | () | method |
public static function set(target:Object, vars:Object):TweenLite
Immediately sets properties of the target accordingly - essentially a zero-duration to() tween with a more intuitive name. So the following lines produce identical results:
TweenLite.set(myObject, {x:100, y:50, alpha:0}); TweenLite.to(myObject, 0, {x:100, y:50, alpha:0});
And of course you can use an array to set the properties of multiple targets at the same time, like:
TweenLite.set([obj1, obj2, obj3], {x:100, y:50, alpha:0});
Parameters
target:Object — Target object (or array of objects) whose properties will be affected.
| |
vars:Object — An object defining the value for each property that should be set. For example, to set mc.x to 100 and mc.y to 200, do this: TweenLite.set(mc, {x:100, y:200});
|
TweenLite — A TweenLite instance (with a duration of 0) which can optionally be inserted into a TimelineLite/Max instance (although it's typically more concise to just use the timeline's set() method).
|
to | () | method |
public static function to(target:Object, duration:Number, vars:Object):TweenLite
Static method for creating a TweenLite instance that animates to the specified destination values (from the current values). The following lines of code all produce identical results:
TweenLite.to(mc, 1, {x:100}); var myTween = new TweenLite(mc, 1, {x:100}); var myTween = TweenLite.to(mc, 1, {x:100});
Each line above will tween the "x"
property of the mc
object
to a value of 100 over the coarse of 1 second. They each use a slightly different syntax,
all of which are valid. If you don't need to store a reference of the tween, just use the
static TweenLite.to( )
call.
Since the target
parameter can also be an array of objects, the following
code will tween the x property of mc1, mc2, and mc3 to a value of 100 simultaneously:
TweenLite.to([mc1, mc2, mc3], 1, {x:100});
Even though 3 objects are animating, there is still only one tween created.
In order to stagger or offset the start times of each object animating, please see
the staggerTo()
method of TimelineLite or TweenMax.
For simple sequencing, you can use the delay
special property
(like TweenLite.to(mc, 1, {x:100, delay:0.5})
),
but it is highly recommended that you consider using TimelineLite (or TimelineMax)
for all but the simplest sequencing tasks. It has an identical to()
method
that allows you to append tweens one-after-the-other and then control the entire sequence
as a whole. You can even have the tweens overlap as much as you want.
Parameters
target:Object — Target object (or array of objects) whose properties this tween affects.
| |
duration:Number — Duration in seconds (or frames if useFrames:true is set in the vars parameter)
| |
vars:Object — An object defining the end value for each property that should be tweened as well as any special properties like onComplete , ease , etc. For example, to tween mc.x to 100 and mc.y to 200 and then call myFunction , do this: TweenLite.to(mc, 1, {x:100, y:200, onComplete:myFunction});
|
TweenLite — TweenLite instance
|
See also