A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Timer does not reset

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    27

    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

  2. #2
    Junior Member
    Join Date
    Dec 2009
    Posts
    13
    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]);
    }
    }

  3. #3
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    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.

  4. #4
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    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.

  5. #5
    Junior Member
    Join Date
    Feb 2010
    Posts
    27
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center