Posted By

chrisaiv on 01/14/08


Tagged

as3


Versions (?)

Who likes this?

19 people have marked this snippet as a favorite

arala22
outbox
meltmetal
THEPWN3R
enajenkins
Winkyboy
mprabhuram
edsonpavoni
SmpleJohn
frankyfish
adrianparr
IsoJon
Chansu
adamzwakk
donaldleegraham
tspitzr
onemanstudio
russdogg
szydlowskijk


AS3: Basic Timer example


 / Published in: ActionScript 3
 

Flash's Timer Class requires two parameters. The first is the delay (in milliseconds), the second is the amount of times you want the delay to fire.

  1. var timer:Timer = new Timer(1000, 2);
  2. timer.addEventListener(TimerEvent.TIMER, blah);
  3. timer.start();
  4.  
  5. function blah(e:TimerEvent):void{
  6. trace("Times Fired: " + e.currentTarget.currentCount);
  7. trace("Time Delayed: " + e.currentTarget.delay);
  8. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: bengoevaerts on February 18, 2010

When e.currentTarget.currentCount = 1 i would like to reset it again to 0. How can i do this? I tried e.currentTarget.currentCount.reset(); and some kind like that ... but it won't work, any ideas?

Posted By: chrisaiv on February 23, 2010

What are you trying to accomplish? Maybe there's another way to solve your problem?

Posted By: ccpotter on May 19, 2010

you can establish a variable separate from the currentCount that increases by one each time the counter blah function is hit.

var timer:Timer = new Timer(1000, 2); var currentIndex:Number = 0; timer.addEventListener(TimerEvent.TIMER, blah); timer.start();

function blah(e:TimerEvent):void{ currentIndex++; if(currentIndex >= 10){ currentIndex = 0; } trace("Times Fired: " + e.currentTarget.currentCount); trace("Time Delayed: " + e.currentTarget.delay); }

Posted By: chrisaiv on July 4, 2010

Very cool! ccpotter, thanks for sharing.

Posted By: IsoJon on August 11, 2010

always good to have a place to copy and paste from, thanks!

Posted By: sidneydekoning on September 27, 2010

@bengoevaerts - you can call Timer.reset() as mentioned here http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/Timer.html

Good luck,

Sidney de Koning

You need to login to post a comment.