The Flash and PHP Bible has been released! The book can be found on Amazon or wherever fine books are sold in your area.
The Flash and PHP Bible has a forum for quick support.
Learn how to create a basic Timer in ActionScript 3.
In this short tutorial we will explore the process of creating a timer, which will move an object when the timer expires.
Start by creating a new Flash file, add a movieclip to the stage and assign an instance name of objectMC.
Once the movieclip is created, the next step is to create the timer code.
var myTimer:Timer = new Timer(1000, 1); myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler); myTimer.start();
That code creates a Timer instance, assigns an event handler and kicks off the timer countdown. The next step is to create the timer handler function.
function timerHandler(evt:TimerEvent):void
{
objectMC.x = 200;
objectMC.y = 200;
}
Now when you test the movie the object will sit on the stage and once the timer is complete the object will move.
What happens if you want to stop the timer? Well that is simple, just call the stop(); method of the Timer class.
myTimer.stop();
You have completed the code required for this example. Feel free to expand on the example and begin using timers in your own code.
Here is the complete code for this example:
// Requires a movieclip with the instance name "objectMC" to be on the stage
var myTimer:Timer = new Timer(1000, 1);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
myTimer.start();
function timerHandler(evt:TimerEvent):void
{
objectMC.x = 200;
objectMC.y = 200;
}
©2004 - 2010 scriptplayground | Privacy Policy | Legal
Validate Site: XHTML CSS | Designed by: Matthew Keefe of mkeefeDESIGN