SKITSANOS FOR RIA

Skitsanos

Friday, May 30, 2008

ActionScript 3 simple timer, sample code.

The code below gives you an example of the wonderful timer class, before this timers were a total pain in ActionScript 2, this new class gives us all the functionality we always had to code around before.

———– code sample

var myTimer:Timer = new Timer(5000,1);

myTimer.addEventListener(TimerEvent.Timer, timerFunction);

function timerFunction(event:TimerEvent):void
{
trace(“Timer function executed”);
}

myTimer.start();



———– end code sample



We first create an instance of the Timer class and tell it we want it to fire every 5 seconds (5000) and to do it only 1 time. Then we create an EventListener and tell it to call our method/function called timerFunction which simply traces some text to the output window. Then finally we just need to tell our timer instance to start. The timer instance will stop after it has executed the specified amount of times (in this case once).



Read other AS3 articles as well...

2 comments:

GrfxGuru said...

This post is from my blog?

http://grfxguru.wordpress.com

Evgenios Skitsanos said...

Well yea, since it links directly to you.

Webware development dedicated blog by Skitsanos R&D Labs. ASP.NET, XML, RIA, Adobe Flex, ActionScript 3, AIR, AJAX, Web 2.0, Backbase, CGI development with RealBasic and other web development issues.
News
Downloads