0 Replies Latest reply on Aug 7, 2006 2:00 AM by flashkiran

    Quiz 2.0  Two Way Navigation

    flashkiran
      hi,

      This is with respect to a quiz application, i am working with.

      We have 2 ways of navigation .

      Either, user will click the next button or previous button, in order to get previous or next question in the quiz as well as there are buttons kept in the left hand side like

      1
      2
      3
      4
      5
      6
      ...

      so, at any time, user can directly click in the left button and navigate to that particular question.


      In my application, i am associating the scoring logic with the click of the next button. If i give the same script in the left hand side buttons, i am not getting my logic to be worked.

      this is the complete script of my Quiz

      -------------- Quiz Code Start Here ---------------

      var arrCorrectAnswer:Array = new Array(1, 2, 3, 4);
      var arrUserAnswer:Array;
      var arrUserAnswerCopy:Array;
      var nCurrentQuestion:Number = 1;
      //var nTotalQuestion:Number=4;
      var nTotalScore:Number = 0;
      var btn_pressed:String;
      var i:Number=0;
      function init() {
      arrUserAnswer = new Array();
      for (var i = 0; i<arrCorrectAnswer.length; i++) {
      arrUserAnswer = null;
      }
      nextFrame();
      //gotoAndStop(2);
      }
      init();

      //next button logic - final score display if we finish all questions (4 in my case)

      next_btn.onRelease = function() {
      btn_pressed = "nxt";
      chk_ans();
      if (nCurrentQuestion >=5) {
      displayFinalAnswer();
      }
      };

      //back button logic

      back_btn.onRelease = function() {
      btn_pressed = "prev";
      prevFrame();
      nCurrentQuestion=nCurrentQuestion-1;
      displayUserAns();


      };


      //function used to check the correct answer

      function chk_ans() {
      if (radioGroup.selection == _level0.r1) {
      arrUserAnswer[nCurrentQuestion-1] = 1;
      } else if (radioGroup.selection == _level0.r2) {
      arrUserAnswer[nCurrentQuestion-1] = 2;
      } else if (radioGroup.selection == _level0.r3) {
      arrUserAnswer[nCurrentQuestion-1] = 3;
      } else if (radioGroup.selection == _level0.r4) {
      arrUserAnswer[nCurrentQuestion-1] = 4;
      } else {
      arrUserAnswer[nCurrentQuestion-1] = null;
      }
      nextFrame();
      resetButtons();
      }

      function resetButtons() {
      r1.selected = false;
      r2.selected = false;
      r3.selected = false;
      r4.selected = false;
      displayUserAns();
      nCurrentQuestion=nCurrentQuestion+1;
      }

      function displayUserAns() {
      if (btn_pressed == "prev") {
      if (arrUserAnswer[nCurrentQuestion-1] == 1) {
      r1.selected = true;
      } else if (arrUserAnswer[nCurrentQuestion-1] == 2) {
      r2.selected = true;
      } else if (arrUserAnswer[nCurrentQuestion-1] == 3) {
      r3.selected = true;
      } else if (arrUserAnswer[nCurrentQuestion-1] == 4) {
      r4.selected = true;
      }
      } else if (btn_pressed == "nxt") {
      if (arrUserAnswer[nCurrentQuestion] == 1) {
      r1.selected = true;
      } else if (arrUserAnswer[nCurrentQuestion] == 2) {
      r2.selected = true;
      } else if (arrUserAnswer[nCurrentQuestion] == 3) {
      r3.selected = true;
      } else if (arrUserAnswer[nCurrentQuestion] == 4) {
      r4.selected = true;
      }
      }
      }

      //function that is used to do the marking (for every right answer, score will added to 3 //units and for every wrong answer, reduced to -1


      function displayFinalAnswer() {
      for (i=0; i<arrCorrectAnswer.length; i++) {
      if (arrUserAnswer
      == arrCorrectAnswer ) {
      nTotalScore = nTotalScore+3;
      trace("The Question"+arrUserAnswer
      +"Score is"+" :"+nTotalScore);
      } else if (arrUserAnswer == null) {
      //trace("The Question"+arrUserAnswer
      +"Score is"+" :"+nTotalScore);
      } else if (arrUserAnswer != arrCorrectAnswer && arrUserAnswer != null) {
      nTotalScore = nTotalScore-1;
      trace("The Question"+arrUserAnswer
      +"Score is"+" :"+nTotalScore);
      //trace(nTotalScore);
      }
      //trace(nTotalScore);
      }
      trace(nTotalScore);
      _root.score = nTotalScore;
      _root.gotoAndStop("score");

      }

      // I have completed the test button

      score_btn.onRelease = function()
      {
      displayUserAnswer();
      displayFinalAnswer();
      next_btn.enabled=false;
      back_btn.enabled=false;
      }


      -------------- Quiz Code Ends Here ---------------


      now, i dont know how to implement the second navigation logic, clicking on the question button link, will go that particular link.

      this is the script i am giving in button 1

      but1.onRelease = function()
      {
      gotoAndPlay(2); //my questions start from 2nd frame, so 1st question in 2nd //Frame
      }


      if i leave it as it is....it is navigating..but the score is not coming.


      can anyone help me out in this regard.

      cheers
      saikiran
      saisen76@hotmail.com