AS2 and AS3.


... onStart:value, ...


value:Function — A function that is called immediately before a tweening starts. It is called once regardless of the number of properties involved on the tweening. The function scope (in which the event is executed) is the target object itself, unless specified by the onStartScope parameter.


// Hides a movieclip, then only shows it when it's time for it to fade in (AS2)
showUp = function() {
	this._visible = true;
myMovieClip._visible = false;
myMovieClip._alpha = 0;
Tweener.addTween(myMovieClip, {_alpha:100, time:1, delay:4, onStart:showUp});
// Similarly, with an anonymous function
myMovieClip._visible = false;
myMovieClip._alpha = 0;
Tweener.addTween(myMovieClip, {_alpha:100, time:1, delay:4, onStart:function() { this._visible = true; }});


The reference passed to this property is a reference to the function only. This roughly means you do not use any kind of parenthesis or parameters when passing the function you wish to call - you need to use the onStartParams parameter for that. For example, this is wrong:

Tweener.addTween(myMC, {_x:10, time:1, onStart:myFunction(), delay:1});

What the above code would do is immediately call the myFunction function, regardless of any time or delay imposed, and actually pass its return value (if any) as the onStart parameter for Tweener. That is, it won't work, and that's not the way actionscript is meant to work. The correct code is as such:

Tweener.addTween(myMC, {_x:10, time:1, onStart:myFunction, delay:1});

This way, you are passing the function itself as the parameter.

In the same vein, you cannot pass parameters for a function by enclosing it with parenthesis. This won't work:

Tweener.addTween(myMC, {_x:10, time:1, onStart:trace("I've started!"), delay:1});

Again, it will call the function immediately, and pass its return value (if any) as the actual parameter. That's usually not what you want to do. The correct way to pass function parameters is with an additional tweening parameter -- as mentioned, onStartParams on this case. This way:

Tweener.addTween(myMC, {_x:10, time:1, onStart:trace, onStartParams:["I've started!"], delay:1});

And remember that, of course, you can always use function calls on any tweening parameter, as long as you know what you're doing - that is, you expect the function to be called immediately and its return value to be the actual tweening parameter used. For example, to get a random destination as a parameter:

var getRandomPosition:Function = function(): Number {
	return Math.random() * 400;
Tweener.addTween(myMC, {_x:getRandomPosition(), time:1});

See also

onStartParams, onStartScope, onUpdate, onComplete, onOverwrite