5 Replies Latest reply on Nov 25, 2010 4:33 AM by smilelilac

    Help! Quiz - need to count score at the end


      I have a working quiz but I want to know how to get the score of the number of correct answers the person got but I can't seem to figure out the code for it. This is my code below. Can someone help me?


      stop();// movie clip waits on buttons

      gloss_mc._visible = false;// set the gloss initially to not visible
      score_int = 0;// score on the quiz is initially zero

      // button functions
      q1_btn.onRelease = function() {
      q2_btn.onRelease = function() {
      q3_btn.onRelease = function() {
      q4_btn.onRelease = function() {

      function scoreQuiz_fnc(ansSelected) {
          trace("scoreQuiz_fnc ("+ansSelected+")");
      // define answer key
      answerkey_arr = new Array();
      answerkey_arr[1] = '2';// the answer to the question on frame 1
      answerkey_arr[2] = '4';// the answer to the question on frame 2
      answerkey_arr[3] = '3';// ... etc.
      answerkey_arr[4] = '4';
      answerkey_arr[5] = '3';
      answerkey_arr[6] = '1';
      answerkey_arr[7] = '3';
      answerkey_arr[8] = '4';
      answerkey_arr[9] = '1';
      answerkey_arr[10] = '2';

      glosskey_arr = new Array();// create array of gloss responses
      glosskey_arr[1] = 'The correct answer is: Congenital heart defect.';
      glosskey_arr[2] = 'The correct answer is: Four areas of the heart are defected because "tetra" means four. ';
      glosskey_arr[3] = 'The correct answer is: Two left valves because there is only a right and left valve.';
      glosskey_arr[4] = 'The correct answer is: Ventricular Septal Defect because this is when there is a hole (septum) between the right and left ventricles..';
      glosskey_arr[5] = 'The correct answer is: Babies because this condition congenital meaning at birth.';
      glosskey_arr[6] = 'The correct answer is: There is not enough oxygen carried within the blood which causes a discolouration in infants.';
      glosskey_arr[7] = 'The correct answer is: Heart murmur because this condition occurs at the heart.';
      glosskey_arr[8] = 'The correct answer is: After crying, during bowel movements or the occurrence of kicking legs in awakening.';
      glosskey_arr[9] = 'The correct answer is: Shunt because you cannot place the other objects in a heart.';
      glosskey_arr[10] = 'The correct answer is: Heart.';

      function nextQuestion_fnc() {
          gloss_mc._visible = false;// hide the gloss
          nextFrame();// advance timeline to the next question

      // score the answer selected by user
      function scoreQuiz_fnc(ansSelected) {
          trace("For question "+_currentframe);
          //if the answer key for this question matches the answer selected
          if (gloss_mc._visible == false) {
              if (answerkey_arr[_currentframe] == ansSelected) {
                  score_int = score_int+1;//add one to the score count
                  nextFrame();// go to next frame
              } else {
                  // show the gloss
                  gloss_mc._visible = true;
                  gloss_mc.gloss_txt.text = glosskey_arr[_currentframe];// insert gloss from the array
                  // end if statement
                  trace("Score is now "+score_int);
      }// end of function

        • 1. Re: Help! Quiz - need to count score at the end
          unamus3d Level 1

          Would it not make sense to have each question on a seperate frame

          then have the selection of answers outputted as movieclip/buttons.


          For all the wrong answers put






          and for the button that is the right answer


          have it do score = score +1;


          so if they press the right answer score will be increased by 1 and then it will move onto next question, if else it will just move on with out increasing score if there wrong.


          just a basic idea, not sure if its what your wanting tho


          once all the score is added you can just out put it using a dynamic text field.

          • 2. Re: Help! Quiz - need to count score at the end
            SynthiaT5 Level 1

            I don't know. This is how my prof taught the class to do it and I am new to ActionScript stuff so I kind of don't want to redo everything. I have a dynamic text box in the last frame for when they are done the quiz. And the output, what I traced shows up and the amount of answers they get right only when they get a question wrong. I just need to get that to show on my last frame where the dynamic text box is.

            • 3. Re: Help! Quiz - need to count score at the end
              unamus3d Level 1

              To get a dynamic text field just drag a text tool and go over to the properties panel and change it from static text to dynamic.

              then u can give it an instance name

              • 4. Re: Help! Quiz - need to count score at the end
                SynthiaT5 Level 1

                Ya, I did that ... I just need to know the code for the number of correct answers to show up in that box. I named the dynamic text box as score_txt and I've tried using the code

                score_txt.text = score_int;

                but that doesn't work and I've tried codes similar to that but none of them work either.

                • 5. Re: Help! Quiz - need to count score at the end
                  smilelilac Level 1

                  Try this


                  Name the dynamic text box in var not at Instance name


                  You will find it in properties panel .By selecting the dynamic text field you will have some properties like var,single line ....ect





                  Try this one


                  this is your code : score_txt.text = score_int;


                  try this :score_txt = score_txt+1;


                  where  score_txt is the instance name or the var name you are assigning to the dynamic text field where you will display the score.



                  Note: Change all of the dynamic text field name "score_int" in the script in to score_txt ,Because you have changed the dynamic text field to score_txt at the beginig of the script also you have score_int = 0.change heare also.



                  If your problem is solved mark this as Answered