Copy link to clipboard
Copied
The goal:
With the timeline stopped, a timer counts to a specified number of seconds, then performs an action (play, gotoAndPlay, etc).
Here's the code cobbled together from tutorials and forum generousity, but how do I set it to fire the action at 30 sec, or 60 sec?
stop();
var timer:Timer = new Timer(20, 100); // Sets delay to 100, repeatCount to 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 will execute when triggered by a TimerEvent.TIMER event
}
timer.addEventListener(TimerEvent.TIMER, timerListener);
//fire the 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 get that the answer's probably in the second line, but what do the 20, 100 correspond to? From my rough test the timer currently runs for about 3 seconds before triggering the event.
FLA posted here: https://my.syncplicity.com/share/kobzidmgnm/as3_timer-CT-simple
Thanks for any guidance...
1 Correct answer
If you look up the Timer class in the Help documentation you will find the answers you seek. If you are not familiar with how to do that, one simple way is to select the word "timer" in the Actions panel code and right click it and choose View Help at the bottom of the menu that appears. The Timer class document should open.
In there you will find that the 20 and the 100 are the delay and repeatCount properties.
Copy link to clipboard
Copied
If you look up the Timer class in the Help documentation you will find the answers you seek. If you are not familiar with how to do that, one simple way is to select the word "timer" in the Actions panel code and right click it and choose View Help at the bottom of the menu that appears. The Timer class document should open.
In there you will find that the 20 and the 100 are the delay and repeatCount properties.
Copy link to clipboard
Copied
I think I get it... Timer(20, 100) means a 20 millisecond delay is repeated 100 times = a 2 second interval. So if I want 30 seconds, I used Timer(10, 3000)
Thanks
Copy link to clipboard
Copied
If you want a 30 second timer and have no use for 10 msec intervals just specify a 30 second delay (30000 msecs).

