1 Reply Latest reply on Nov 19, 2010 1:20 PM by kglad

    Drag/Drop Multiple Choice Question, why is "Submit" disabled?

    TaylorJumbo Level 1

      I'm updating a Drag-Drop Multiple Choice question.  I didn't create the question and am inexperienced with ActionScript coding.

       

      The updated question shows the correct answes in order BUT the question won't let you select the "Submit" button until you have moved the answers around.

       

      Since the question is right from the start, the user should be able to select the "submit" button even without moving the answers.

       

      I appreciate any leads on what to do.  Here is the code.

       

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

       

      stop();
      _level0.showScore();
      _level0.disableNext();
      var answerArray:Array = ["", 1, 2, 3];
      var statusArray:Array = ["", 1, 2, 3];
      var tempArray:Array = new Array();
      tempArray.push("");
      var positionArray:Array = ["", -45.65, 39.6, 123.85];
      var targetArray:Array = [""];
      var targetMc:MovieClip;


      var countArr = [""];
      var feedback_arr = [""];
      feedback_arr.push("Good work! You are on your way to showing Lisa your recommended unit. Click <b>Forward</b> to continue.");
      feedback_arr.push("The SuperSTAR interactions are not in the correct order. 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.");


      for (var i = 1; i<=3; i++) {
      var tempObject:Object = new Object();
      tempObject.x = dashboard["ch_"+i]._x;
      tempObject.y = dashboard["ch_"+i]._y;
      tempObject.i = i;
      tempArray.push(tempObject);
      }


      function init() {
      baseMc = dashboard;
      for (var i = 1; i<=max; i++) {
        trace("mcs::"+baseMc);
        baseMc["ch_"+i].i = i;
        targetArray.push(baseMc["ch_"+i]);
        initDepth = this.getDepth();
        baseMc["ch_"+i].onPress = function() {
         startDrag(this, false, -310, -50, -250, 125);
         this.swapDepths(this.getNextHighestDepth());
        };
        baseMc["ch_"+i].onRelease = baseMc["ch_"+i].onReleaseOutside=function () {
         this.stopDrag();
         this.swapDepths(this.initDepth);
         //trace("dragNum::"+this.i);
         var dragNum = this._name.split("_")[1];
         //var ins_name = this._droptarget.split("/")[3];
         //var targMc = ins_name.split("_")[0];
         //trace("ins_name::"+ins_name+"targ mc::"+targMc)
         var optionNum = ins_name.split("_")[1];
         //trace("this:"+this.i+"targMc::"+this._droptarget);
         switch (this.i) {
          case 1 :
           if (compare(this)) {
            trace("In if::"+targetMc);
            swapMcs_1(targetMc.i);
            checkStatus();
           } else {
            trace("In else::");
            this._x = tempArray[this.i].x;
            this._y = tempArray[this.i].y;
           }
           break;
          case 2 :
           if (compare(this)) {
            trace("In if::"+targetMc);
            swapMcs_2(targetMc.i);
            checkStatus();
           } else {
            trace("In else::");
            this._x = tempArray[this.i].x;
            this._y = tempArray[this.i].y;
           }
           break;
          case 3 :
           if (compare(this)) {
            trace("In if::"+targetMc);
            swapMcs_3(targetMc.i);
            checkStatus();
           } else {
            trace("In else::");
            this._x = tempArray[this.i].x;
            this._y = tempArray[this.i].y;
           }
           break;
          default :
           break;
         }
        };
      }
      baseMc.submit_btn.onRelease = function() {
        this.enabled = true;
        for (var i= 1; i<=max; i++) {
         baseMc["ch_"+i].enabled = true;
        }
        showFeedback();
      };

      baseMc.tryAgain_btn.onRelease = function() {
        this._visible = false;
        baseMc.submit_btn.enabled = false;
        reset();
        showTry = false;
      };
      baseMc.showAnswer_btn.onRelease = function() {
        this.enabled = false;
        dashboard.ch_1.gotoAndStop(2);
        dashboard.ch_2.gotoAndStop(2);
        dashboard.ch_3.gotoAndStop(2);

        //baseMc.feedback_mc.gotoAndStop(1);
        setToPosition();
      };
      }


      function compare(mc) {
      for (var j:Number = 1; j<=3; j++) {
        if (mc !== targetArray[j]) {
         if (mc.hitTest(targetArray[j])) {
          trace("true, "+targetArray[j]);
          targetMc = targetArray[j];
          return true;
         } else {
          trace("false, "+targetArray[j]);
         }
        }
      }
      return false;
      }

      function swapMcs_1(mc) {
      trace("mc::"+mc);
      if (mc == "2") {
        for (var i = 1; i<=3; i++) {
         if (baseMc["ch_"+i].i == 2) {
          baseMc["ch_"+i]._x = tempArray[1].x;
          baseMc["ch_"+i]._y = tempArray[1].y;
          baseMc["ch_"+i].i = 1;
         } else if (baseMc["ch_"+i].i == 1) {
          baseMc["ch_"+i]._x = tempArray[2].x;
          baseMc["ch_"+i]._y = tempArray[2].y;
          baseMc["ch_"+i].i = 2;
         }
        }
        /*statusArray.length = 0;
        statusArray.push("");
        statusArray.push(2);
        statusArray.push(1);
        statusArray.push(3);*/

      } else if (mc == 3) {
        for (var i = 1; i<=3; i++) {
         if (baseMc["ch_"+i].i == 1) {
          baseMc["ch_"+i]._x = tempArray[1].x;
          baseMc["ch_"+i]._y = tempArray[1].y;
          baseMc["ch_"+i].i = 1;
         } else if (baseMc["ch_"+i].i == 2) {
          baseMc["ch_"+i]._x = tempArray[2].x;
          baseMc["ch_"+i]._y = tempArray[2].y;
          baseMc["ch_"+i].i = 2;
         } else if (baseMc["ch_"+i].i == 3) {
          baseMc["ch_"+i]._x = tempArray[3].x;
          baseMc["ch_"+i]._y = tempArray[3].y;
          baseMc["ch_"+i].i = 3;
         }
        }
        /*statusArray.length = 0;
        statusArray.push("");
        statusArray.push(2);
        statusArray.push(3);
        statusArray.push(1);*/
      }


      }

      function swapMcs_2(mc) {
      trace("mc:::::::"+mc);
      if (mc == "3") {
        for (var i = 1; i<=3; i++) {
         if (baseMc["ch_"+i].i == 3) {
          baseMc["ch_"+i]._x = tempArray[2].x;
          baseMc["ch_"+i]._y = tempArray[2].y;
          baseMc["ch_"+i].i = 2;
         } else if (baseMc["ch_"+i].i == 2) {
          baseMc["ch_"+i]._x = tempArray[3].x;
          baseMc["ch_"+i]._y = tempArray[3].y;
          baseMc["ch_"+i].i = 3;
         }
        }
        /*statusArray.length = 0;
        statusArray.push("");
        statusArray.push(1);
        statusArray.push(3);
        statusArray.push(2);*/
      } else if (mc == "1") {
        for (var i = 1; i<=3; i++) {
         if (baseMc["ch_"+i].i == 1) {
          baseMc["ch_"+i]._x = tempArray[2].x;
          baseMc["ch_"+i]._y = tempArray[2].y;
          baseMc["ch_"+i].i = 2;
         } else if (baseMc["ch_"+i].i == 2) {
          baseMc["ch_"+i]._x = tempArray[1].x;
          baseMc["ch_"+i]._y = tempArray[1].y;
          baseMc["ch_"+i].i = 1;
         }
        }
        /*statusArray.length = 0;
        statusArray.push("");
        statusArray.push(2);
        statusArray.push(1);
        statusArray.push(3);*/
      }
      }

      function swapMcs_3(mc) {
      trace("movieclip::"+mc);
      if (mc == "1") {
        for (var i = 1; i<=3; i++) {
         if (baseMc["ch_"+i].i == 2) {
          baseMc["ch_"+i]._x = tempArray[2].x;
          baseMc["ch_"+i]._y = tempArray[2].y;
          baseMc["ch_"+i].i = 1;
         } else if (baseMc["ch_"+i].i == 2) {
          baseMc["ch_"+i]._x = tempArray[3].x;
          baseMc["ch_"+i]._y = tempArray[3].y;
          baseMc["ch_"+i].i = 3;
         } else if (baseMc["ch_"+i].i == 3) {
          baseMc["ch_"+i]._x = tempArray[1].x;
          baseMc["ch_"+i]._y = tempArray[1].y;
          baseMc["ch_"+i].i = 1;
         }

        }
        /*statusArray.length = 0;
        statusArray.push("");
        statusArray.push(3);
        statusArray.push(1);
        statusArray.push(2);*/

      } else if (mc == "2") {
        for (var i = 1; i<=3; i++) {
         if (baseMc["ch_"+i].i == 2) {
          baseMc["ch_"+i]._x = tempArray[3].x;
          baseMc["ch_"+i]._y = tempArray[3].y;
          baseMc["ch_"+i].i = 3;
         } else if (baseMc["ch_"+i].i == 3) {
          baseMc["ch_"+i]._x = tempArray[2].x;
          baseMc["ch_"+i]._y = tempArray[2].y;
          baseMc["ch_"+i].i = 2;
         }
        }
        /*statusArray.length = 0;
        statusArray.push("");
        statusArray.push(1);
        statusArray.push(3);
        statusArray.push(2);*/
      }
      }


      function checkStatus() {
      trace("In function checkStatus::");

      baseMc.submit_btn.enabled = true;

      }


      function showAnswer() {
      setQuizAnswers();
      _level0.enableNext();
      baseMc.feedback_mc.gotoAndPlay("start");
      baseMc.feedback_mc.base.gotoAndStop(4);
      //baseMc.feedback_mc.base.feedback_txt.text = feedback_arr[3];
      baseMc.showAnswer_btn._visible = true;
      baseMc.showBtnShad._visible = true;
      }


      function showFeedback() {

      _level0.setScenarioQuizAttended(0);
      statusArray.length = 0;
      statusArray.push("");
      for (var j = 1; j<=3; j++) {
        //trace("clip::"+baseMc["ch_"+j]+"clip x ::"+baseMc["ch_"+j]._x+"::clip y:"+"clip x ::"+baseMc["ch_"+j]._y);
        if (baseMc["ch_"+j]._y == -45.65) {
         //trace("1::"+baseMc["ch_"+j]._name.split("_")[1]);
         statusArray[1] = baseMc["ch_"+j]._name.split("_")[1];
         var index:Number = baseMc["ch_"+j]._name.split("_")[1];
         _level0.lastPosition[index] = -45.65;
        } else if (baseMc["ch_"+j]._y == 39.6) {
         //trace("1::"+baseMc["ch_"+j]._name.split("_")[1]);
         statusArray[2] = baseMc["ch_"+j]._name.split("_")[1];
         var index:Number = baseMc["ch_"+j]._name.split("_")[1];
         _level0.lastPosition[index] = 39.6;
        } else if (baseMc["ch_"+j]._y == 123.85) {
         //trace("1::"+baseMc["ch_"+j]._name.split("_")[1]);
         statusArray[3] = baseMc["ch_"+j]._name.split("_")[1];
         var index:Number = baseMc["ch_"+j]._name.split("_")[1];
         _level0.lastPosition[index] = 123.85;
        }
        trace("j::"+j+"lastPosition"+_level0.lastPosition[j]);

      }
      //trace("status Array::"+statusArray);
      //trace("answer Array::"+answerArray);
      count++;

      trace("In showFeedback::"+count);

      for (var i = 1; i<answerArray.length; i++) {
        if (statusArray[i] == answerArray[i]) {
         countArr.push(1);
        }
        //trace("countArr:"+countArr+"length::"+countArr.length)      
      }
      if (countArr.length == statusArray.length) {
        if (!_level0.reloadBoolean) {
         trace("BOOL::"+_level0.reloadBoolean);
        }
        setQuizAnswers();
        _level0.enableNext();
        _level0.updateScore(0);
        trace("success"+feedback_arr[1]+"reload boolean::"+_level0.reloadBoolean);
        baseMc.feedback_mc.gotoAndPlay("start");
        baseMc.feedback_mc.base.gotoAndStop(2);
        //baseMc.feedback_mc.base.feedback_txt.text = feedback_arr[1];
      } else {
        _level0.updateScore(1);
        trace("Wrong::"+feedback_arr[2]+"count::"+count);
        if (count == 2) {
         showAnswer();
         setToPosition();
        } else {
         baseMc.feedback_mc.gotoAndPlay("start");
         baseMc.feedback_mc.base.gotoAndStop(3);
         //baseMc.feedback_mc.base.feedback_txt.text = feedback_arr[2];
         if (showTry) {
          baseMc.tryAgain_btn._visible = true;
         }
        }
        setQuizAnswers();
      }


      }

      function reset() {

      for (var i = 1; i<=max; i++) {
        baseMc["ch_"+i].enabled = true;
        baseMc["ch_"+i]._x = tempArray[i].x;
        baseMc["ch_"+i]._y = tempArray[i].y;
        baseMc["ch_"+i].i = i;
        baseMc.feedback_mc.gotoAndStop(1);
        statusArray[i] = "";
        countArr.length = 0;
        countArr.push("");
        lastPosition.length = 0;
        lastPosition.push("");
      }
      }


      function resetToPrevPosition() {
      var baseMc = dashboard;
      trace("In func resetToPrevPosition::");
      for (var i = 1; i<=max; i++) {
        baseMc["ch_"+i]._y = _level0.lastPosition[i];
        trace("y pos::"+baseMc["ch_"+i]._y);
        //baseMc.feedback_mc.gotoAndStop(1);
      }
      }

       

      function setToPosition() {
      var baseMc = dashboard;
      for (var i = 1; i<=max; i++) {
        baseMc["ch_"+i].gotoAndStop(2);
        baseMc["ch_"+i]._y = positionArray[i];
        baseMc["ch_"+i].i = i;
      }
      }


      function setQuizAnswers() {
      _level0.pushAnswers(statusArray.toString());
      }

      if (!_parent.alreadyAnswered) {
      init();
      } else {
      trace("In else:::::");
      _level0.hideScore();
      //setSelectedAns();
      setToPosition();
      //resetToPrevPosition();
      _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);
         }
        }

      }

      }