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

Project does not run well with timer

Guest
Apr 04, 2016 Apr 04, 2016

Hi.

I have created one quiz project and everything run well before I add timer function into it. When I hit "pause" timer, the timer stop, the buttons are all disabled for Q1 (this are good as what the quiz was supposed to be). But when I "restart" the timer, to move to the next question, it will redirect me to the last page and end the quiz. It was supposed to redirect me to the next question. Help needed!   Thank you

import flash.display.SimpleButton;

stop();

var pause_btn:SimpleButton;

var finalString:String = '';

//var finalString2:String = '';

var _list:Array = ["Q1", "Q2", "Q3,"Q4,"Q5 ","Q6","Q7","Q8 ","Q9","Q10","Q11","Q12", "Q13","Q14", "Q15", "Q16","Q17", "Q18", "Q19", "Q20"];

var _marks:Array = [];

var i:int;

var myscore = 0;

////////////////////////////////////////////

buttonA.buttonMode = true;

buttonB.buttonMode = true;

buttonC.buttonMode = true;

buttonD.buttonMode = true;

skip_btn.buttonMode = true;

score_txt.text = myscore;

question_txt.text = _list[0];

buttonA.label_txt.text = "A.";

buttonB.label_txt.text = "B.";

buttonC.label_txt.text = "C.";

buttonD.label_txt.text = "D.";

skip_btn.label_txt.text = "Skip";

buttonA.label_txt.mouseEnabled = buttonB.label_txt.mouseEnabled = buttonC.label_txt.mouseEnabled = buttonD.label_txt.mouseEnabled = skip_btn.label_txt.mouseEnabled = false;

buttonA.addEventListener(MouseEvent.CLICK, q1);

buttonB.addEventListener(MouseEvent.CLICK, q1);

buttonC.addEventListener(MouseEvent.CLICK, q1);

buttonD.addEventListener(MouseEvent.CLICK, q1);

skip_btn.addEventListener(MouseEvent.CLICK, q1);

function q1(event:MouseEvent):void

{

  if(event.currentTarget == buttonA)

  {

  _marks.push("Your answer");

  }

  else if(event.currentTarget == buttonB)

  {

  _marks.push("Your answer");

  }

  else if(event.currentTarget == buttonC)

  {

  _marks.push("Your answer");

  myscore+=5;

  }

  else if(event.currentTarget == buttonD)

  {

  _marks.push("Your answer");

  }

  else if(event.currentTarget == skip_btn)

  {

  _marks.push("Skip");

  }

      buttonA.removeEventListener(MouseEvent.CLICK, q1);

   buttonB.removeEventListener(MouseEvent.CLICK, q1);

   buttonC.removeEventListener(MouseEvent.CLICK, q1);

   buttonD.removeEventListener(MouseEvent.CLICK, q1);

   skip_btn.removeEventListener(MouseEvent.CLICK, q1);

  nextFrame();

}

/*myTimer.start();*/

var endTime1:int = getTimer();

endTime1 = 40*60*1000;  //adjust endTime to 40 minutes in the future.

var countdownTimer1:Timer = new Timer(1000);

countdownTimer1.addEventListener(TimerEvent.TIMER, updateTime1);

countdownTimer1.start();

function updateTime1(e:TimerEvent):void

{

    endTime1 -= 1000

    var timeLeft:Number = endTime1;

  var seconds:Number = Math.floor(timeLeft / 1000);

  var minutes:Number = Math.floor(seconds / 60);

  seconds %= 60;

  minutes %= 60;

  var sec:String = seconds.toString();

  var min:String = minutes.toString();

  if (sec.length < 2) {

    sec = "0" + sec;

  }

  if (min.length < 2) {

    min = "0" + min;

  }

  var time:String = min + ":" + sec;

  timer_txt.text = time;

}

// this button will pause the timer using Boolean variable:

var pause1:Boolean = false;

pause_btn.addEventListener(MouseEvent.CLICK, onClick1);

function onClick1(e:MouseEvent):void

{

    if(pause1 == false)

    {

        countdownTimer1.stop();

        pause1 = true;

  buttonA.buttonMode = false;

  buttonB.buttonMode = false;

  buttonC.buttonMode = false;

  buttonD.buttonMode = false;

  skip_btn.buttonMode = false;

  //resume_btn.label_txt.text = "Jeda";

  //buttonA.label_txt.mouseEnabled = buttonB.label_txt.mouseEnabled = buttonC.label_txt.mouseEnabled = skip_btn.label_txt.mouseEnabled = resume_btn.label_txt.mouseEnabled = false;

  buttonA.removeEventListener(MouseEvent.CLICK, q1);

  buttonB.removeEventListener(MouseEvent.CLICK, q1);

  buttonC.removeEventListener(MouseEvent.CLICK, q1);

  buttonD.removeEventListener(MouseEvent.CLICK, q1);

  skip_btn.removeEventListener(MouseEvent.CLICK, q1);

    }

    else

    {

        countdownTimer1.start();

        pause1 = false;

  buttonA.buttonMode = buttonB.buttonMode = buttonC.buttonMode = buttonD.buttonMode = skip_btn.buttonMode = true;

  //resume_btn.label_txt.text = "Mula";

  //buttonA.label_txt.mouseEnabled = buttonB.label_txt.mouseEnabled = buttonC.label_txt.mouseEnabled = skip_btn.label_txt.mouseEnabled = resume_btn.label_txt.mouseEnabled = true;

  buttonA.addEventListener(MouseEvent.CLICK, q1);

  buttonB.addEventListener(MouseEvent.CLICK, q1);

  buttonC.addEventListener(MouseEvent.CLICK, q1);

  buttonD.addEventListener(MouseEvent.CLICK, q1);

  skip_btn.addEventListener(MouseEvent.CLICK, q1);

    }

}

/*var home:Boolean = false;

homeqz1.addEventListener(MouseEvent.CLICK, onClick);

function onClick(e:MouseEvent):void

{

    if(home == false)

    {

        countdownTimer1.stop();

        home = true;

    }

}

TOPICS
ActionScript
348
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
LEGEND ,
Apr 05, 2016 Apr 05, 2016

I do not see any code in what you show that sends you to either the next question or the end.  What code do you have in place that is supposed to introduce the next question?

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
Guest
Apr 05, 2016 Apr 05, 2016

The code that I used to go to the next frame is nextFrame();

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
LEGEND ,
Apr 05, 2016 Apr 05, 2016
LATEST

I am assuming you click the pause_btn to either pause or unpause it based on the code you show, which has no relation to the other buttons (A,B,C,etc) that would result in a call to the nextFrame() function.  If you think it is somehow the nextFrame() function that is getting executed then try putting a trace(event.currentTarget); in that function to try to track down where the command is coming from.  I would guess that it is not that command that is sending you to the end.

If you happen to be programming in the non-strict mode, I suggest you change it to be so that you get the benefit of errors that you might not otherwise see.

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