-
Timer does not reset
Hello,
Ik got a game with a timer. When the game is finished you can play it again and the SWF file loads again. Everything is reset exept the timer. A new one starts but the old one is on the background.
The timer is the only code thats on the timeline... Is that the problem here?
I cant get the timer working in my AS file...
This is the code on the timeline:
Actionscript Code:
var timer:Timer = new Timer(60, 1000); timer.addEventListener(TimerEvent.TIMER, countdown); timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerDone); timer.start(); function countdown(e:Event) { myText.text = String(1000 - timer.currentCount); } function timerDone(e:TimerEvent):void{ gotoAndStop(3); for (var i:int = 0; i < _cards.length; i++){ removeChild(_cards[i]); } }
Anybody an idea what I'm doing wrong?
Tnx
-
did you try to add timer.stop() ?
function timerDone(e:TimerEvent):void{
gotoAndStop(3);
timer.stop();
for (var i:int = 0; i < _cards.length; i++){
removeChild(_cards[i]);
}
}
-
newb of many sorts
lets say that your code is on frame 1. your timer is declared and the listeners are applied. if you go back to frame 1, you will be declaring a new timer, leaving the old one to continue its duties until the garbage collector decides to pick it up.
try declaring the timer on frame 1, then on frame 2 call timer.reset() and timer.start(); then when you start a new game, always go to frame 2.
Search first, asked questions later.
-
newb of many sorts
though, it would be best if you could have the timer in your AS file. What happens when you try?
Search first, asked questions later.
-
Hi,
I solved it:-)
The timer started on frame 1... now I cleared frame one and the timer starts at frame 2... Now when I restart and go to frame 2 again he start a new one:-S
It works so.. :-)
Thank you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|