Introduction

Tweener is a class for Actionscript 2 and 3, meaning it’s a piece of code you can call and reuse on your own movies. This is just its documentation - for more information on the extension itself, please visit the official website at Google Code.

For a quick explanation on how to install Tweener, see Installation first.

If you are used to Actioncript 1, prototypes, or #includes, and don't know how to use a real class yet, please read the how to use a class page for a brief introduction on the issue.

If you are used to MC Tween and want to know the differences on the syntax between MC Tween and Tweener, also check Differences between MC Tween and Tweener.

Brief explanation

Tweener is a static class - that is, a class that allows you to run methods on it, or call its properties, but that never lets you create instances from it. This means that, with Tweener, you never create a new object - you simply tells Tweener to do something for you.

Tweener works on the idea that, instead of setting the value of a given property of a given object directly, as in myMC._x = 10, you can tell that property to create a transition to that value - by doing this transition or tweening, you can control your numeric data in a more fluid way, also by using easing equations in this process. Doing slides, fades, and all kinds of animation is the result of this kind of manipulation: by making a property or variable go to one value or the other fluidly, not immediately. Rich transitions and animations with simple code is the aim of Tweener.

With Tweener, you write your code by adding new tweenings or transitions to the movie, using the method addTween. Like this (AS2 version):

Tweener.addTween(myMovie, {_x:10, _y:10, time:1, transition:"linear"});

Or this (AS3 version):

Tweener.addTween(myMovie, {x:10, y:10, time:1, transition:"linear"});

This will move the object myMovie on screen, going to the position 10,10, in 1 second, using a linear animation (other transition types are available).

The final value is an absolute value, not a relative one. This means that, if you want to, say, move myMovie 10 pixels to the right (instead of sliding it to column 10), you would do this (in AS2):

Tweener.addTween(myMovie, {_x:myMovie._x+10, time:1, transition:"linear"});

Also notice you can chain tweenings sequentially, creating complex animations, by using delays. For example, to move myMovie to column 10, then to column -10, you would do (in AS2):

Tweener.addTween(myMovie, {_x:10, time:1, transition:"linear"});
Tweener.addTween(myMovie, {_x:-10, time:1, delay:1, transition:"linear"});

Notice the use of the delay property, that tells the animation to wait a bit (the same ammount of the previous transition) before starting. This specified delay property allows you to create complex animations that are not necessarily chained together sequentially, but start at a given time; you could create animations that act on different objects with arbritrary ammounts of time to wait for any of these transitions.

The cool thing with Tweener is that this addTween method allows you to use a plethora of different optional tweening parameters, giving you control to a lot of different transition properties.

The important thing to notice is that Tweener isn't just a class used to create just animations. It's, instead, a class used to create transitions - doing tweenings on any numeric property of any object - which can be used for many purposes, including visual animation. It's not restricted to the normal Actionscript classes like MovieClip or TextField either; you can use it to tween properties of your own classes and objects, like moving the cameraX and cameraY properties of your game rendering engine, the currentTemperature of your own Thermometer class object, the travelPosition of your train simulation movie, the currentStrength of each of your spectrum analyzer graph bars, and so on and so forth.

See the menu at the left for a listing of the available methods and other options. Don't forget to also check the online examples for a bunch of practical uses of Tweener, including their source files.