addTween()

Availability

AS2 and AS3.

Usage

Tweener.addTween(target:Object, tweeningParameters:Object):Void

Parameters

target:Object — Any object that will suffer a tweening. These objects are usually MovieClip, TextField, or Sound instances, or any other custom object with a numeric property that needs to be tweened.

tweeningParameters:Object — An object containing various properties of the original object that you want to tween on the original objects, with their final values assigned (some special properties are also allowed), as well as some built-in Tweener properties used when defining tweening parameters. This is like the recipe for the tweening, declaring both what will be tweened, and how.

Description

The core of Tweener, it’s used when creating new tweenings. It instructs certain properties of an object to do a transition to a certain value, taking a certain time. For example, you could instruct the _x of myMC to reach value 100 in 2 seconds, using a linear transition equation, for a simple MovieClip sliding animation.

This method has a pretty loose syntax, with a few hard-coded parameters, allowing for a plethora of different transition options to be declared.

There are many different options available, so check the documentation for each different feature on the tweening parameters page, and see other uncommon properties you can use on the special properties page.

Returns

Nothing.

Examples

// Slide a movieclip to a new position in 0.5 seconds (AS2)
Tweener.addTween(myMovieClip, {_x:10, time:0.5});
// Slide a movieclip to a new position in 0.5 seconds (AS3)
Tweener.addTween(myMovieClip, {x:10, time:0.5});
// Fade in on a movieclip in 2 seconds (AS2)
myMovieClip._alpha = 0;
Tweener.addTween(myMovieClip, {_alpha:100, time:2});
// Fade in on a movieclip in 2 seconds (AS3)
myMovieClip.alpha = 0;
Tweener.addTween(myMovieClip, {alpha:1, time:2});
// Do a transition on both _x and on _alpha
Tweener.addTween(myMovieClip, {_x:10, _alpha:100, time:0.5});
// Do a tweening using other transition type
Tweener.addTween(myTextField, {_y:200, time:0.7, transition:"linear"});
// Using delays to create animation sequences
Tweener.addTween(myMovieClip, {_x:20, time:0.5});
Tweener.addTween(myMovieClip, {_x:0, time:0.5, delay: 0.5});
// Using tweener 'templates'
var fadeIn:Object = {_alpha:100, time:1};
Tweener.addTween(myMovieClip, fadeIn);
// Using events to fade out then disappear (normal function)
disappear = function() {
	this._visible = false;
};
Tweener.addTween(myMovieClip, {_alpha:0, time:1, onComplete:disappear});
// Using events to fade out then disappear (anonymous in-line function)
Tweener.addTween(myMovieClip, {_alpha:0, time:1, onComplete:function() { this._visible = false; }});
// Using events to fade out then disappear (using the _autoAlpha special property)
Tweener.addTween(myMovieClip, {_autoAlpha:0, time:1});
// More complex events
fGo = function() { trace ("I'll go!"); };
fGoing = function() { trace ("I'm going!"); };
fGone = function() { trace ("I'm gone!"); };
Tweener.addTween(myMovieClip, {_alpha:0, time:1, onStart:fGo, onUpdate:fGoing, onComplete:fGone});
// Assigning a value immediately (with no time or delay)
Tweener.addTween(myMovieClip, {_alpha:100});
// Using other special properties (that are not related to a variable/property)
Tweener.addTween(mySoundObject, {_sound_volume:100, time:1});
Tweener.addTween(myMovieClip, {_frame:10, time:2.5});

See also

pauseTweens, resumeTweens, removeTweens, removeAllTweens, addCaller, Tweening parameters, Special properties