Flash ActionScript Tutorial: Loop Animation with Tween Class and Multiple yoyo Methods
The yoyo Method will instruct the tweened animation to play in reverse from its last direction of tweened objects.
Flash Tutorial Content:
Actually you can use multiple yoyo Methods with the tweened objects. This flash actionscript animation tutorial will use two yoyo Methods with the tweened football.
The finished Flash Movie of this tutorial is shown as above. By adding two yoyo Methods to the tweened football, it can created a more interesting loop animation.
Flash ActionScript Codes:
//import transition classes
import fl.transitions.*;
import fl.transitions.easing.*;
//Destination location the specified movie clips will move to
var x2:Number = 420;
var y2:Number = 200;
//Tween animation in x-axis
var tweenX:Tween = new Tween(football_mc, "x", Regular.easeOut, football_mc.x, x2, 3, true);
//Tween animation in y-axis
var tweenY:Tween = new Tween(football_mc, "y", Regular.easeOut, football_mc.y, y2, 3, true);
//Add Listener to tweenX
//Listen when the motion of tweenX FINISHED
//Will call moveMore function when motion of tweenX FINISHED
tweenX.addEventListener(TweenEvent.MOTION_FINISH, moveMore);
function moveMore(event:TweenEvent):void {
output_txt.text = "When tweenX motion is FINISHED." + "\n" +
"The motion will be played in reverse." + "\n" +
"The function moveMore will be called whenever a motion is finished.";
//Instructs tweenX animation to play in reverse
//from its last direction
tweenX.yoyo();
//Instructs tweenY animation to play in reverse
//from its last direction
tweenY.yoyo();
}
Download Flash Source File:
Remarks:
This Flash ActionScript tutorial used two yoyo Methods with the tweened object..