About continuing animations using the continueTo() method

Using the Tween class demonstrates how to use the Tween class in your applications. However, if you want to move the ball after the initial animation is complete, there are at least two ways you can do it. One solution is to reanimate the ball by using the onMotionFinished event handler. However, the Tween class offers a simpler solution, the continueTo() method. The continueTo() method instructs the tweened animation to continue from its current value to a new value, as the following ActionScript shows:

import mx.transitions.Tween;
import mx.transitions.easing.*;
var ball_tween:Tween = new Tween(ball_mc, "_x", Regular.easeIn, 0, 300, 3, true);
ball_tween.onMotionFinished = function() {
    ball_tween.continueTo(0, 3);
};

After the initial tween finishes, the ball_mc movie clip tweens back to its original position at 0 pixels. The following snippet (edited for brevity) shows the function prototype for the continueTo() method:

function continueTo(finish:Number, duration:Number):Void {
    /* omitted to save space. */
}

Only two arguments pass to the continueTo() method, instead of the seven arguments for the Tween constructor method, as the following snippet shows:

function Tween (obj, prop, func, begin, finish, duration, useSeconds) {
    /* omitted to save space. */
}

The five parameters that aren't required by the continueTo() method (obj, prop, func, begin, and useSeconds) use the arguments that you defined earlier in the call to the Tween class. When you call the continueTo() method, you assume that the obj, prop, func (easing type), and useSeconds arguments are the same as in the earlier call to the Tween class. The continueTo() method uses the finish value from the call to the Tween class, instead of specifying a value for the begin argument, as the following ActionScript shows:

import mx.transitions.Tween;
import mx.transitions.easing.*;
var ball_tween:Tween = new Tween(ball_mc, "_x", Regular.easeIn, 0, 300, 3, true);
ball_tween.onMotionFinished = function() {
     ball_tween.continueTo(0, 3);
};

This code moves the ball_mc instance along the x-axis from 0 pixels to 300 pixels in three seconds. After the animation finishes, the onMotionFinished event handler is triggered and calls the continueTo() method. The continueTo() method tells the target object (ball_mc) to proceed from its current position and animate for three seconds along the x-axis to 0 pixels and to use the same easing method. You use the values specified in the call to the Tween constructor method for any parameters that you don't define in the continueTo() method. If you don't specify a duration for the continueTo() method, it uses the duration you specify in the call to the Tween constructor.