Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to reset my Timer

Explorer ,
Apr 24, 2013 Apr 24, 2013

Hello!

I have a question and I hope I can find a solution here.I have a short quiz and I want to allow the user only 30 seconds per question to give a right answer.

I have a "start" button that triggers a countdown timer for the first time. Then, I want each time the user clicks  the button "next", the countdown to start again counting from 30 to 0. This is what I have tried so far:

var fl_SecondsToCountDown:Number = 30;

var fl_CountDownTimerInstance:Timer = new Timer(1000, fl_SecondsToCountDown);

fl_CountDownTimerInstance.addEventListener(TimerEvent.TIMER, fl_CountDownTimerHandler);

start_btn.addEventListener(MouseEvent.CLICK,startCountdown);

next_btn.addEventListener(MouseEvent.CLICK, goNext);

function fl_CountDownTimerHandler(event:TimerEvent):void

{

          seconds_txt.text = String(fl_SecondsToCountDown);

          fl_SecondsToCountDown--;

}

function startCountdown(e:MouseEvent):void{

          fl_CountDownTimerInstance.start();

}

function goNext(e:MouseEvent):void{

                    fl_CountDownTimerInstance.reset();

}

Now, what it does it's just stopping the countdown at 25 seconds, for example, and then if I ask it to start again, it starts where it has left off, instead of going back to 30 seconds again.

Thanks a lot!

TOPICS
ActionScript
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 24, 2013 Apr 24, 2013

use:

function fl_CountDownTimerHandler(event:TimerEvent):void

{

          seconds_txt.text = String(fl_CountDownTimerInstance.repeatCount-fl_CountDownTimerInstance.currentCount);

       

}

Translate
Community Expert ,
Apr 24, 2013 Apr 24, 2013

use the reset() method:

fl_CountDownTimerInstance.reset();

// then apply the start() method when you want your timer to (re)start

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 24, 2013 Apr 24, 2013

I have tried that now. I have put fl_CountDownTimerInstance.reset(); in a function, and then when the user clicks "Next" I have put fl_CountDownTimerInstance.start();

But what it does is simply stopping the countdown at a certain point, and then when I click "Next", it continues from where it has left off. It's like it just pauses.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 24, 2013 Apr 24, 2013

no, it resets the timer so it stops after 30 more calls.

it does not reset fl_SecondsToCountDown to 30, though.  in fact, you should NOT be re-defining that unless that serves some purpose.

you should be checking the timer's currentCount to see how many calls have been made and how many are remaining, if that's what you are trying to access by using fl_SecondsToCountDown.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 24, 2013 Apr 24, 2013

fl_SecondsToCountDown helps me decrement the number of seconds. I don't know another alternative to that...

function fl_CountDownTimerHandler(event:TimerEvent):void

{

          seconds_txt.text = String(fl_SecondsToCountDown);

         fl_SecondsToCountDown--;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 24, 2013 Apr 24, 2013

use:

function fl_CountDownTimerHandler(event:TimerEvent):void

{

          seconds_txt.text = String(fl_CountDownTimerInstance.repeatCount-fl_CountDownTimerInstance.currentCount);

       

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 24, 2013 Apr 24, 2013

Yes it worked! Thank you very very much for your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 24, 2013 Apr 24, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines