API Documentation | All Packages | All Classes | Index | Frames No Frames |
Class TweenNano

Package | com.greensock
Class | public class TweenNano

TweenNano is a super-lightweight (1.6k in AS3 and 2k in AS2) version of TweenLite and is only recommended for situations where you absolutely cannot afford the extra 3.1k (4.7k total) that the normal TweenLite engine would cost and your project doesn't require any plugins. Normally, it is much better to use TweenLite because of the additional flexibility it provides via plugins and its compatibility with TimelineLite and TimelineMax. TweenNano can do everything TweenLite can do with the following exceptions:

- No Plugins - One of the great things about TweenLite is that you can activate plugins in order to add features (like autoAlpha, tint, blurFilter, etc.). TweenNano, however, doesn't work with plugins.
- Incompatible with TimelineLite and TimelineMax - Complex sequencing and management of groups of tweens can be much easier with TimelineLite and TimelineMax, but TweenNano instances cannot be inserted into TimelineLite or TimelineMax instances.
- Slight speed decrease - Under very heavy loads, TweenNano won't perform quite as well as TweenLite, but it is extremely unlikely that you'd notice unless you're tweening thousands of objects simultaneously.
- Fewer overwrite modes - You can either overwrite all or none of the existing tweens of the same object (overwrite:true or overwrite:false) in TweenNano. TweenLite, however, can use OverwriteManager to expand its capabilities and use modes like AUTO, CONCURRENT, PREEXISTING, and ALL_ONSTART (see http://www.greensock.com/overwritemanager/ for details).
- Compared to TweenLite, TweenNano is missing the following methods/properties:
  - pause()
  - play()
  - resume()
  - restart()
  - reverse()
  - invalidate()
  - onStart
  - onInit
  - defaultEase
  - easeParams
  - currentTime
  - startTime
  - totalTime
  - paused
  - reversed
  - totalDuration

SPECIAL PROPERTIES:
Any of the following special properties can optionally be passed in through the vars object (the third parameter):

- delay : Number Amount of delay in seconds (or frames for frames-based tweens) before the tween should begin.
- useFrames : Boolean If useFrames is set to true, the tweens's timing mode will be based on frames. Otherwise, it will be based on seconds/time.
- ease : Function Use any standard easing equation to control the rate of change. For example, `Elastic.easeOut`. The Default is Regular.easeOut.
- onUpdate : Function A function that should be called every time the tween's time/position is updated (on every frame while the timeline is active)
- onUpdateParams : Array An Array of parameters to pass the onUpdate function
- onComplete : Function A function that should be called when the tween has finished
- onCompleteParams : Array An Array of parameters to pass the onComplete function.
- immediateRender : Boolean Normally when you create a from() tween, it renders the starting state immediately even if you define a delay which in typical "animate in" scenarios is very desirable, but if you prefer to override this behavior and have the from() tween render only after any delay has elapsed, set `immediateRender` to false.
- overwrite : Boolean Controls how other tweens of the same object are handled when this tween is created. Here are the options:
  - false (NONE): No tweens are overwritten. This is the fastest mode, but you need to be careful not to create any tweens with overlapping properties of the same object that run at the same time, otherwise they'll conflict with each other.
    `TweenNano.to(mc, 1, {x:100, y:200});
    TweenNano.to(mc, 1, {x:300, delay:2, overwrite:false}); //does NOT overwrite the previous tween.`
  - true (ALL_IMMEDIATE): This is the default mode in TweenNano. All tweens of the same target are completely overwritten immediately when the tween is created, regardless of whether or not any of the properties overlap.
    `TweenNano.to(mc, 1, {x:100, y:200});
    TweenNano.to(mc, 1, {x:300, delay:2, overwrite:true}); //immediately overwrites the previous tween`

EXAMPLES:
Tween the the MovieClip "mc" to an alpha value of 0.5 (50% transparent) and an x-coordinate of 120 over the course of 1.5 seconds like so:
`import com.greensock.TweenNano;
TweenNano.to(mc, 1.5, {alpha:0.5, x:120});`
To tween the "mc" MovieClip's alpha property to 0.5, its x property to 120 using the `Back.easeOut` easing function, delay starting the whole tween by 2 seconds, and then call a function named "onFinishTween" when it has completed (it will have a duration of 5 seconds) and pass a few parameters to that function (a value of 5 and a reference to the mc), you'd do so like:
`import com.greensock.TweenNano;
import com.greensock.easing.Back;
TweenNano.to(mc, 5, {alpha:0.5, x:120, ease:Back.easeOut, delay:2, onComplete:onFinishTween, onCompleteParams:[5, mc]});
function onFinishTween(param1:Number, param2:MovieClip):void {
trace("The tween has finished! param1 = " + param1 + ", and param2 = " + param2);
}`
If you have a MovieClip on the stage that is already in it's end position and you just want to animate it into place over 5 seconds (drop it into place by changing its y property to 100 pixels higher on the screen and dropping it from there), you could:
`import com.greensock.TweenNano;
import com.greensock.easing.Elastic;
TweenNano.from(mc, 5, {y:"-100", ease:Elastic.easeOut});`
NOTES:

- The base TweenNano class adds about 1.6k to your Flash file.
- Passing values as Strings will make the tween relative to the current value. For example, if you do `TweenNano.to(mc, 2, {x:"-20"});` it'll move the mc.x to the left 20 pixels which is the same as doing `TweenNano.to(mc, 2, {x:mc.x - 20});` You could also cast it like: `TweenNano.to(mc, 2, {x:String(myVariable)});`
- Kill all tweens for a particular object anytime with the `TweenNano.killTweensOf(mc);`
- You can kill all delayedCalls to a particular function using `TweenNano.killTweensOf(myFunction);` This can be helpful if you want to preempt a call.
- If some of your tweens don't appear to be working, read about the `overwrite` special property above - it is most likely an overwriting issue that could be solved by adding `overwrite:false` to your vars object.
- Use the `TweenNano.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).
- If you find this class useful, please consider joining Club GreenSock which not only helps to sustain ongoing development, but also gets you bonus plugins, classes and other benefits that are ONLY available to members. Learn more at http://www.greensock.com/club/

Copyright 2011, GreenSock. All rights reserved. This work is subject to the terms in http://www.greensock.com/terms_of_use.html or for corporate Club GreenSock members, the software agreement that was issued with the corporate membership.

Public Properties

| Property | Defined by
--- | --- | ---
|  | duration : Number Duration of the tween in seconds (or in frames if "useFrames" is true). | TweenNano
|  | target : Object Target object whose properties this tween affects. | TweenNano
|  | useFrames : Boolean Indicates that frames should be used instead of seconds for timing purposes. | TweenNano
|  | vars : Object Stores variables (things like "alpha", "y" or whatever we're tweening, as well as special properties like "onComplete"). | TweenNano

Public Methods

| Method | Defined by
--- | --- | ---
|  | TweenNano(target:Object, duration:Number, vars:Object) Constructor | TweenNano
|  | complete(skipRender:Boolean = false):void Forces the tween to completion. | TweenNano
|  | delayedCall(delay:Number, onComplete:Function, onCompleteParams:Array = null, useFrames:Boolean = false):TweenNano [static] Provides a simple way to call a function after a set amount of time (or frames). | TweenNano
|  | from(target:Object, duration:Number, vars:Object):TweenNano [static] Static method for creating a TweenNano instance that tweens in the opposite direction compared to a TweenNano.to() tween. | TweenNano
|  | kill():void Kills the tween, stopping it immediately. | TweenNano
|  | killTweensOf(target:Object, complete:Boolean = false):void [static] Kills all the tweens of a particular object, optionally forcing them to completion too. | TweenNano
|  | renderTime(time:Number):void Renders the tween at a particular time (or frame number for frames-based tweens) WITHOUT changing its startTime, meaning if the tween is in progress when you call renderTime(), it will not adjust the tween's timing to continue from the new time. | TweenNano
|  | to(target:Object, duration:Number, vars:Object):TweenNano [static] Static method for creating a TweenNano instance which can be more intuitive for some developers and shields them from potential garbage collection issues that could arise when assigning a tween instance to a variable that persists. | TweenNano

Property detail

duration | property

`public var duration:Number`

Duration of the tween in seconds (or in frames if "useFrames" is true).

target | property |

`public var target:Object`

Target object whose properties this tween affects. This can be ANY object, not just a DisplayObject.

useFrames | property |

`public var useFrames:Boolean`

Indicates that frames should be used instead of seconds for timing purposes. So if useFrames is true and the tween's duration is 10, it would mean that the tween should take 10 frames to complete, not 10 seconds.

vars | property |

`public var vars:Object`

Stores variables (things like "alpha", "y" or whatever we're tweening, as well as special properties like "onComplete").

Constructor detail

TweenNano | () | constructor

`public function TweenNano(target:Object, duration:Number, vars:Object)`

Constructor

Parameters

| `target:Object` — Target object whose properties this tween affects. This can be ANY object, not just a DisplayObject.
| `duration:Number` — Duration in seconds (or in frames if "useFrames" is true)
| `vars:Object` — An object containing the end values of the properties you're tweening, like {x:100, y:50}. It can also contain special properties like "onComplete", "ease", "delay", etc.

Method detail

complete | () | method

`public function complete(skipRender:Boolean = false):void`

Forces the tween to completion.

Parameters

| `skipRender:Boolean` (default = `false`)`` — To skip rendering the final state of the tween, set skipRender to true.

delayedCall | () | method |

`public static function delayedCall(delay:Number, onComplete:Function, onCompleteParams:Array = null, useFrames:Boolean = false):TweenNano`

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. For example:
`TweenNano.delayedCall(1, myFunction, ["param1", 2]);
function myFunction(param1:String, param2:Number):void {
trace("called myFunction and passed params: " + param1 + ", " + param2);
}`

Parameters

| `delay:Number` — Delay in seconds (or frames if "useFrames" is true) before the function should be called
| `onComplete:Function` — Function to call
| `onCompleteParams:Array` (default = `null`)`` — An Array of parameters to pass the function.
| `useFrames:Boolean` (default = `false`)`` — If the delay should be measured in frames instead of seconds, set useFrames to true (default is false)

Returns

| `TweenNano` — TweenNano instance

from | () | method |

`public static function from(target:Object, duration:Number, vars:Object):TweenNano`

Static method for creating a TweenNano instance that tweens in the opposite direction compared to a TweenNano.to() tween. In other words, you define the START values in the vars object instead of the end values, and the tween will use the current values as the end values. This can be very useful for animating things into place on the stage because you can build them in their end positions and do some simple TweenNano.from() calls to animate them into place. 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` object so that it will wait to render until the tween actually begins. 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:
`TweenNano.from(mc, 1.5, {alpha:0, delay:2});`

Parameters

| `target:Object` — Target object whose properties this tween affects. This can be ANY object, not just a DisplayObject.
| `duration:Number` — Duration in seconds (or frames if "useFrames" is true)
| `vars:Object` — An object containing the start values of the properties you're tweening like {x:100, y:50}. It can also contain special properties like "onComplete", "ease", "delay", etc.

Returns

| `TweenNano` — TweenNano instance

kill | () | method |

`public function kill():void`

Kills the tween, stopping it immediately.

killTweensOf | () | method |

`public static function killTweensOf(target:Object, complete:Boolean = false):void`

Kills all the tweens of a particular object, optionally forcing them to completion too.

Parameters

| `target:Object` — Object whose tweens should be immediately killed
| `complete:Boolean` (default = `false`)`` — Indicates whether or not the tweens should be forced to completion before being killed.

renderTime | () | method |

`public function renderTime(time:Number):void`

Renders the tween at a particular time (or frame number for frames-based tweens) WITHOUT changing its startTime, meaning if the tween is in progress when you call renderTime(), it will not adjust the tween's timing to continue from the new time. The time is based simply on the overall duration. For example, if a tween's duration is 3, renderTime(1.5) would render it at the halfway finished point.

Parameters

| `time:Number` — time (or frame number for frames-based tweens) to render.

to | () | method |

`public static function to(target:Object, duration:Number, vars:Object):TweenNano`

Static method for creating a TweenNano instance which can be more intuitive for some developers and shields them from potential garbage collection issues that could arise when assigning a tween instance to a variable that persists. The following lines of code all produce exactly the same result:
`var myTween:TweenNano = new TweenNano(mc, 1, {x:100});
TweenNano.to(mc, 1, {x:100});
var myTween:TweenNano = TweenNano.to(mc, 1, {x:100});`

Parameters

| `target:Object` — Target object whose properties this tween affects. This can be ANY object, not just a DisplayObject.
| `duration:Number` — Duration in seconds (or frames if "useFrames" is true)
| `vars:Object` — An object containing the end values of the properties you're tweening, like {x:100, y:50}. It can also contain special properties like "onComplete", "ease", "delay", etc.

Returns

| `TweenNano` — TweenNano instance