3 Replies Latest reply on Jun 9, 2015 10:50 AM by kglad

    Quiz codes

    maluchrider

      Good morning everyone!

       

      I am a beginning Flash CS5 user and I was wondering if anybody could help me. I succeeded in making a very simple quiz in Action Script 2 and wanted to develop my abilities: I've been struggling to add following features to my quiz: e.g. a 15-second timer on every question frame ( I can only produce a timer that lasts the whole quiz and does not reset) and a life-counting device (i.e. if you get the answer wrong three times, you lose, whereas if you simply make a mistake you get a chance to re-answer the question). Thank you very much in advance, I underline that I am a complete beginner and therefore I kindly ask for very straightforward help! Thank you again

        • 1. Re: Quiz codes
          kglad Adobe Community Professional & MVP

          for an as2 timer, you can use a setTimeout function.

           

          // initialize once

          var timerTO:Number;

           

          //when a question is presented:

          clearTimeout(timerTO);

          timerTO = setTimeout(timerF,15000);

           

          function timerF():Void{

          // 15 seconds is up

          }

           

          function questionAnsweredF():Void{

          // stop the timer

          clearTimeout(timerTO);

          }

           

          and for your life-counting use a variable. eg,

           

          var lives:Number=3;

           

          //whenever a question is answered incorrect decrement lives and check it it's == 0.

          • 2. Re: Quiz codes
            maluchrider Level 1

            Thank you for the answer, but I haven't fully understood (sorry I am a big newbie). How do I tag the questions wrong and correct? I used to convert them into buttons and the right one allowed the player to proceed to the next frame.

            • 3. Re: Quiz codes
              kglad Adobe Community Professional & MVP

              add listeners to your buttons.  the one that's associated with the correct answer should call a correct function (eg, correctF) and the others should call an incorrect function (eg, incorrectF).

               

              eg, you could use:

               

              function correctF(e:MouseEvent):void{

              clearTimeout(timerTO);

              // increment a score

              // advance to the next question

              }

              function incorrectF(e:MouseEvent):void{

              clearTimeout(timerTO);

              lives--;

              if(lives==0){

              gameoverF();

              } else {

              // advance to the next question

              }

              }

               

              function gameoverF():void{

              //do whatever

              }