Timer Class Reciprocal Animation Flash ActionScript Tutorial
This Flash Timer Class animation shows how to do a reciprocal animation or sequence animation with Timer Class. A movie clip (a bird) on the stage will be rotate up and down infinitely.
Flash Tutorial Content:
In this Flash ActionScript Timer Class tutorial, we do a simple flash sequence animation with Timer Class.
The complete Flash Movie of this tutorial is shown as above. The bird is looking down and up infinitely.
Flash ActionScript Codes:
//Tween class lets you to move, resize, and fade movie clips
import fl.transitions.Tween;
//easing classes lets you do some elastic motion of movie clips
import fl.transitions.easing.*;
//import the TweenEvent class
//allow create a listener to catch the event when a tween finish.
import fl.transitions.TweenEvent;
//Declare and use later
var tweenRotationBody:Tween;
var tweenRotationTail:Tween;
var rotateDirection:String;
//Create a Timer object and store it in a variable called myClock.
//The timer will trigger every 3000 milliseconds (3 seconds)
//1000 milliseconds = 1 second
//3000 milliseconds = 3 seconds
//The repeatCount is zero, i.e. timer will trigger infinitely
//Summary:
//Create a Timer instance that will trigger every 3 seconds infinitely
var myClock:Timer = new Timer(3000, 0);
//Timer object created will not start automatically
//You have to start it
myClock.start();
//Add an event listener to the timer object (myClock)
//The event that listen is called TIMER which will be trigger every 3 seconds
//Every time the TIMER event is triggered, it will call the birdRotation function
myClock.addEventListener(TimerEvent.TIMER, birdRotation);
//Set the bird rotation direction
rotateDirection = "down";
//Function to rotate the bird's body and tail
//The rotation direction depends on the value of rotateDirection
function birdRotation(evt:TimerEvent):void {
rotateDirection = "up"
//Bird's body rotation DOWN tween animation
tweenRotationBody = new Tween(bird_mc, "rotation", Regular.easeOut, 0, 10, 2.5, true);
//Bird's Tail rotation UP tween animation
tweenRotationTail = new Tween(tail_mc, "rotation", Regular.easeOut, 0, 10, 2.5, true);
rotateDirection = "down"
//Bird's body rotation UP tween animation
tweenRotationBody = new Tween(bird_mc, "rotation", Regular.easeOut, 10, 0, 2.5, true);
//Bird's Tail rotation DOWN tween animation
tweenRotationTail = new Tween(tail_mc, "rotation", Regular.easeOut, 10, 0, 2.5, true);
}
Download Flash Source File:
Remarks:
Up to now, we use only one Timer in our Flash Movies. Actually you can use more than one Timer in a Flash Movie. In the next Flash ActionScript Timer Class tutorial, we will use three Timers to do a more interesting animation.