Understanding a code-based timer


the goal:

with timeline stopped, timer counts specified number of seconds, performs action (play, gotoandplay, etc).

 

here's code cobbled tutorials , forum generousity, how set fire action @ 30 sec, or 60 sec?

 

 

stop(); var timer:timer = new timer(20, 100); // sets delay 100, repeatcount 100 timer.addeventlistener(timerevent.timer, stopper); function stopper(event:timerevent):void {     switch (timer.currentcount) {         case timer.repeatcount:                     timertext.text = "done";             timer.reset();             break;     } }  function timerlistener (e:timerevent):void {            gotoandplay("2");   // code here execute when triggered timerevent.timer event } timer.addeventlistener(timerevent.timer, timerlistener);   //fire timer timer.start();  //setup reset button resetbutton.addeventlistener(mouseevent.mouse_down, resetbut);  //reset timer on call function resetbut(event:mouseevent):void { timertext.text = ""; timer.reset(); timer.start(); }   

 

i answer's in second line, 20, 100 correspond to? rough test timer runs 3 seconds before triggering event.

 

fla posted here: https://my.syncplicity.com/share/kobzidmgnm/as3_timer-ct-simple

thanks guidance...

if timer class in documentation find answers seek.  if not familiar how that, 1 simple way select word "timer" in actions panel code , right click , choose view @ bottom of menu appears.  timer class document should open.

 

in there find 20 , 100 delay , repeatcount properties.



More discussions in ActionScript 3


adobe

Comments