MovieClip.tween(), TextField.tween()

Availability

Flash Player 6.

Usage

my_mc.tween(property, pEnd, seconds, animType, delay, callback, extra1, extra2)

Parameters

property One or more properties to tween. Accepts the following formats:

pEnd end property value(s). If more than one property is tweened, you may now pass a single end value which will apply to all.

seconds Duration of tween (number). Defaults to 2 if null or ommitted. Pass 0 to apply the change with no tween.

animType
Animation equation type (string, function or object from custom easing tool) defaults to "easeOutExpo"

string as animType

You can use following strings as types of animation (easing equations by Robert Penner)

"linear",
"easeInQuad","easeOutQuad","easeInOutQuad","easeOutInQuad"
"easeInCubic","easeOutCubic","easeInOutCubic","easeOutInCubic"
"easeInQuart","easeOutQuart","easeInOutQuart","easeOutInQuart"
"easeInQuint","easeOutQuint","easeInOutQuint","easeOutInQuint"
"easeInSine","easeOutSine","easeInOutSine","easeOutInSine"
"easeInExpo","easeOutExpo","easeInOutExpo","easeOutInExpo"
"easeInCirc","easeOutCirc","easeInOutCirc","easeOutInCirc"
"easeInElastic","easeOutElastic","easeInOutElastic","easeOutInElastic"
"easeInBack","easeOutBack","easeInOutBack","easeOutInBack"
"easeInBounce","easeOutBounce","easeInOutBounce""easeOutInBounce"

example:
my_mc.tween("_x",100,3,"easeOutElastic")

function as animType:

you can use easing function generator from Timothee Groleau to generate your function: e.g.:

waveEasing = function(t,b,c,d){

    // ... code from generator 

}; 

my_mc.tween("_x",100,3,waveEasing);

   

object as animType:

you can use custom easing tool from menu window->other panels ->custom easing tool
object must have properties pts (list of control point),ease (function) e.g.:

customEasing = {};

// ...paste easing-panel-generated code here

my_mc.tween("_x",100,3,customEasing);



*this easing is bit slower than previous two methods

delay delay in seconds to start animation (number) defaults to 0

my_mc.('_x', 200,0.5);
my_mc.('_x', 400,0.5,'easeoutcirc',0.5) //half-second delay
my_mc.tween('_width', 300,1,'easeoutelastic',1); //1-sec delay
my_mc.tween('_height', 300,1,'easeoutelastic',2); // 2-sec delay
my_mc.colorTo(0xFF0000,1,'easeinexpo',3); //3-sec delay


callback function to be called when finished (function, string, or object with scope, func, args params)

function as callback:

function onEnd(){

	trace("onEnd");

}

my_mc.tween("_x",100,1,"linear",0,onEnd);


// scope of function is automatically set to my_mc._parent

object as callback

You can pass a generic Object, { }, with the properties:

func - callback function, may also now be a string if scope is defined
scope - scope where callback should execute
args - array of arguments to be passed to the function

updfunc - called on every tween-motion update. Function, or string if updscope is defined
updscope - scope of update function (this object)
updargs - array of arguments passed to update function

startfunc - called on start of tween. Function, or string if startscope is defined
startscope - scope of start function (this object)
startargs - array of arguments passed to start function

* internal mechanism is: func.apply(scope,args)

// on _root

game={};

game.players = ["john","steve"];

game.showScore = function(id, score){

	trace("(this==_root.game) is "+(this==_root.game));	

	trace(this.players[id] + " has " + score + " points");

}



// somewhere in nested movieclip

var callback = {scope: _root.game, func: _root.game.showScore, args:[1,39]};

my_mc.tween("_x",100,1,"linear", 0, callback);



/* Shorthand version: callback-obj is written in-line + string used for func

my_mc.tween("_x",100,1,"linear",0,{scope: _root.game, func: "showScore", args:[1,39]});

*/



//output after finishing tween:



(this==_root.game) is true

steve has 39 points


string as callback

Callbacks can also be passed as a string version of the full function call, like "_root.gotoAndPlay(8)", and the tweening prototype will attempt to parse it. Note however that sometimes it's tough for the engine to parse primitive datatypes correctly, so for instance strings and numbers can get confused. If you're trying to pass more than one argument, don't put any spaces between them.

my_mc.tween("_x",100,1,"linear",0, "_root.gotoAndPlay(8)"); // here 8 ends up as string instead of number

To try and clear up typing you can set variables in advance for the arguments passed:

function callMe(my_obj, my_nr, my_bool) {
 trace(my_obj +">> typeof(my_obj) is "+ typeof(my_obj));
 trace(my_nr +">> typeof(my_nr) is "+ typeof(my_nr));
 trace(my_bool +">> typeof(my_bool) is "+ typeof(my_bool));
}
test_obj = {name: "test", id: 10};
test_bool = true;
test_nr = 99;
my_mc.tween("_x",100,1,"linear",0,"_root.callMe(test_obj,test_nr,test_bool)");


extra1 optional animation parameter.
means AMPLITUDE (a) when animType *elastic
means OVERSHOOT AMOUNT (s) when animType *back

extra2
optional animation parameter.
means PERIOD (p) when animType = *elastic

Returns

Nothing.