1 Reply Latest reply on Nov 19, 2010 9:20 AM by TaylorJumbo

    Updating Multiple Choice Answers

    TaylorJumbo

      I'm updating some multiple choice quesitons in a Flash-based, eLearing module.

       

      How can I update the code so if the user gets the question wrong twice, only answer 1 is shown as correct?

       

      I appreciate any tips or direction on how to make this change.

       

      ------------------------------------------------------------------------------------------ --------------------------------------------------------

       

      _level0.showScore();
      _level0.disableNext();
      var answerArray = ["", "1", "", "1", "1"];
      var statusArray = ["", "", "", "", ""];
      var optionNum;


      var valueArr = ["", 1];
      var countArr = [""];
      var feedback_arr = [""];
      feedback_arr.push("Excellent! You’ve made a great first impression on Lisa. Click <b>Forward</b> to continue.");
      feedback_arr.push("Sorry, your selection is not correct. To attempt the question once again, click the <b>Try Again</b> button.");
      feedback_arr.push("I’m sorry. Your response is still not correct. Click <b>Forward</b> to continue.");


      function mcq() {

      init();
      }

      function init() {
      baseMc = dashboard;
      baseMc.tryAgain_btn._visible = false;
      trace("submit btn::"+baseMc.submit_btn);
      for (var i = 1; i<=max; i++) {
        baseMc["ch_"+i].bg._visible = false;
        baseMc["ch_"+i].onRelease = function() {
         optionNum = this._name.split("_")[1];
         frameNo = (boolArray[optionNum] == false) ? 2 : 1;
         if (frameNo == 2) {
          boolArray[optionNum] = true;
          statusArray[optionNum] = 1;
         } else {
          boolArray[optionNum] = false;
          statusArray[optionNum] = "";
         }

         this.chk.gotoAndStop(frameNo);
         checkStatus();
        };

      }
      baseMc.submit_btn.onRelease = function() {
        this.enabled = false;
        for (var i = 1; i<=max; i++) {
         baseMc["ch_"+i].enabled = false;
        }

        showFeedback();
      };

      baseMc.tryAgain_btn.onRelease = function() {
        this._visible = false;
        baseMc.submit_btn.enabled = false;
        reset();
        showTry = false;

      };
      }

      function checkStatus() {
      var count:Number = 0;
      for (var i = 1; i<=max; i++) {
        if (statusArray[i] == 1) {
         count++;
        }
      }
      if (count>=1) {
        baseMc.submit_btn.enabled = true;
      }else if(count<=0){
        baseMc.submit_btn.enabled = false
      }

      }


      function showAnswer() {
      setQuizAnswers();
      _level0.enableNext();
      for (var j = 1; j<valueArr.length; j++) {
        baseMc["ch_"+valueArr[j]].final_mc._visible = true;
        baseMc["ch_"+valueArr[j]].chk.gotoAndStop(2);
      }
      baseMc.feedback_mc.gotoAndPlay("start");
      baseMc.feedback_mc.base.gotoAndStop(3);
      //baseMc.feedback_mc.base.feedback_txt.text = feedback_arr[3];
      }


      function getStatusCount() {

      for (var i = 0; i<=statusArray.length; i++) {
        if (statusArray[i] == 1) {
         statusCount++;
        }
      }
      }

      function showFeedback() {

      getStatusCount();
      count++;
      for (var i = 1; i<answerArray.length; i++) {
        if (statusArray[i] == answerArray[i] && statusArray[i] != "") {
         countArr.push(1);

        } else {
         if (statusArray[i] == 1) {
          trace("else::::::");
          if (count == 2) {
           baseMc["ch_"+i].chk.gotoAndStop(3);
          }
         }
        }

      }

      //trace("count Array::"+countArr+"value Array::"+valueArr);
      //trace("count array length:"+countArr.length+"value array length::"+valueArr.length+"status array length::"+statusCount);


      if ((countArr.length == valueArr.length) && (statusCount<=valueArr.length)) {
        _level0.updateScore(0);
        _level0.setScenarioQuizAttended(0);
        trace("success"+feedback_arr[1]);
        setQuizAnswers();
        _level0.enableNext();
        baseMc.feedback_mc.gotoAndPlay("start");
        baseMc.feedback_mc.base.gotoAndStop(1);
        //baseMc.feedback_mc.base.feedback_txt.text = feedback_arr[1];
      } else if (countArr.length != 1 && countArr.length<valueArr.length) {
        _level0.updateScore(1);
        _level0.setScenarioQuizAttended(0);
        trace("Partial::"+feedback_arr[2]);
        if (count == 2) {
         showAnswer();
        } else {
         baseMc.feedback_mc.gotoAndPlay("start");
         baseMc.feedback_mc.base.gotoAndStop(2);
         //baseMc.feedback_mc.base.feedback_txt.text = feedback_arr[2];
         if (showTry) {
          baseMc.tryAgain_btn._visible = true;
         }
        }
      } else if (countArr.length<2 || (statusCount>valueArr.length)) {
        _level0.updateScore(2);
        _level0.setScenarioQuizAttended(0);
        trace("Wrong::"+feedback_arr[3]);
        if (count == 2) {
         showAnswer();
        } else {
         baseMc.feedback_mc.gotoAndPlay("start");
         baseMc.feedback_mc.base.gotoAndStop(2);
         //baseMc.feedback_mc.base.feedback_txt.text = feedback_arr[2];
         if (showTry) {
          baseMc.tryAgain_btn._visible = true;
         }
        }
      }
      }

      function reset() {
      for (var i = 1; i<=max; i++) {
        baseMc["ch_"+i].enabled = true;
        baseMc["ch_"+i].chk.gotoAndStop(1);
        baseMc.feedback_mc.gotoAndStop(1);
        boolArray[i] = false;
        statusArray[i] = "";
        countArr.length = 0;
        countArr.push("");
        statusCount = 1;
      }
      }
      function setQuizAnswers() {
      _level0.pushAnswers(statusArray.toString());
      }
      if (!_parent.alreadyAnswered) {
      mcq();
      } else {
      _level0.hideScore();
      setSelectedAns();
      _level0.enableNext();
      }
      function setSelectedAns() {
      var str:String = _level0.getAnswersSet();
      count = 1;
      statusArray = new Array();
      statusArray = str.split(",");
      baseMc = dashboard;
      for (var i = 1; i<answerArray.length; i++) {
        if (statusArray[i] == answerArray[i] && statusArray[i] != "") {
         baseMc["ch_"+i].chk.gotoAndStop(2);
         trace(baseMc["ch_"+i].chk);
        } else {
         if (statusArray[i] == 1) {
          baseMc["ch_"+i].chk.gotoAndStop(3);
         }
        }

      }
      showAnswer();
      baseMc.feedback_mc._visible = false;
      }
      stop();