Skip navigation

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”);


———– 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 fiinally 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).



  1. TIMER needs to be capitalized otherwise you will get one of those horribly useless error messages from the 2bit compiler.

    myTimer.addEventListener(TimerEvent.Timer, timerFunction);

    should be:

    myTimer.addEventListener(TimerEvent.TIMER, timerFunction);

    Also, if you copy and past, retype the quotation marksin the trace statement.

    Thanks for the posting, a great example!

  2. Good catch on the TIMER thanks, seems there is some character alterations going on between my copy and paste into my blog poster on the quotations.

    • GjaG
    • Posted January 14, 2009 at 4:42 pm
    • Permalink

    how can you flash the message exactly 200 ms?
    Is there a method to test whether it is displayed exactly 200 ms?
    By the way, great posting!

  3. A good question,

    Do you mean that you want a msg to appear at 200ms into a timer that is longer in length that 200ms?

    • GjaG
    • Posted January 15, 2009 at 2:24 pm
    • Permalink

    Thanks for you fast reply.
    I want to flash a word for a period of exactly 200 ms on the screen. It is for scientific purposes, therefore I can not be more lenient.
    I assume that 200 ms is not a problem for modern screens. Still I would like to find a method to test whether the duration that the stimulus was visible, was exactly 200 ms.

  4. Hmmm,

    Well you can simply change the time count for 200 milliseconds but I am wondering if you can rely of the Flash player to be that accurate. I have to say that I have never considered the Flash player to be that accurate, however if anyone can help please post and let us know. I’ll see if I can find more answers for you.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: