3 Replies Latest reply on Jun 17, 2009 6:58 PM by stewart-mccoy

    Reset button for drag and drop?

    stewart-mccoy

      I've designed a drag and drop game and I would like to add a button that resets both the draggable objects and the counter so that the game starts fresh and can be replayed.

       

      Also, I would like the button to appear after all the draggable objects have been placed on their corresponding targets. Thanks in advance for your help!

       

      Here's a link to the FLA:

       

      http://www.stewart-mccoy.info/files/hazmat_dragdrop.fla

       

      Below is the AS2 scripting:

       

      // Drag and Drop
      // Original by Alex Fish. Modified by Stewart McCoy.

       

      var allCorrect = 0;
      var reply = "Begin by dragging each placard to its target classification on the rear of the truck.";
      // check if all answers
      // are correct
      this.onEnterFrame= function(){
          if(this.allCorrect==4){
              this.reply = "Congrats, you're on your way to becoming a HAZMAT expert! Click the next button to continue.";
          }
      }

       

      not_set_yet.onRelease = function() {
         
      }

       

      //====== variables ========

      var fixedX:Number = compressed._x;
      var fixedY:Number = compressed._y;
      var fixedX2:Number = flammable._x;
      var fixedY2:Number = flammable._y;
      var fixedX3:Number = oxidizers._x;
      var fixedY3:Number = oxidizers._y;
      var fixedX4:Number = corrosive._x;
      var fixedY4:Number = corrosive._y;

       

      //======== end variables ========

      //======== drag and drop functionality =========

       

      //-------- begin compressed --------------
      compressed.onPress = function() {
          startDrag(this);
          this._parent.reply.txt="";
      };

      compressed.onRelease = function() {
          if(compressed.hitTest(targetcompressed)){
              compressed._x = targetcompressed._x;
              compressed._y = targetcompressed._y;
              feedback.text = "That's correct. Now finish placing the remaining placards.";
              this._parent.allCorrect +=1;
          } else {
              compressed._x = fixedX;
              compressed._y = fixedY;
              feedback.text = "Try again!";
          }
          stopDrag();
      };

       

      //-------- end compressed ------------------------

       

      //-------- begin flammable ----------------------

       

      flammable.onPress = function() {
          startDrag(this);
          this._parent.reply.txt="";
      };

      flammable.onRelease = function() {
          if(flammable.hitTest(targetflammable)){
              flammable._x = targetflammable._x;
              flammable._y = targetflammable._y;
              feedback.text = "That's correct. Now finish placing the remaining placards.";
              this._parent.allCorrect +=1;
          } else {
              flammable._x = fixedX2;
              flammable._y = fixedY2;
              feedback.text = "Try again!";
          }
          stopDrag();
      };

       

      //-------- end flammable ------------------------

       

      //-------- begin oxidizers ----------------------

       

      oxidizers.onPress = function() {
          startDrag(this);
          this._parent.reply.txt="";
      };

      oxidizers.onRelease = function() {
          if(oxidizers.hitTest(targetoxidizers)){
              oxidizers._x = targetoxidizers._x;
              oxidizers._y = targetoxidizers._y;
              feedback.text = "That's correct. Now finish placing the remaining placards.";
              this._parent.allCorrect +=1;
          } else {
              oxidizers._x = fixedX3;
              oxidizers._y = fixedY3;
              feedback.text = "Try again!";
          }
          stopDrag();
      };

       

      //-------- end oxidizers ------------------------

       

      //-------- begin corrosive ----------------------

       

      corrosive.onPress = function() {
          startDrag(this);
          this._parent.reply.txt="";
      };

      corrosive.onRelease = function() {
          if(corrosive.hitTest(targetcorrosive)){
              corrosive._x = targetcorrosive._x;
              corrosive._y = targetcorrosive._y;
              feedback.text = "That's correct. Now finish placing the remaining placards.";
              this._parent.allCorrect +=1;
          } else {
              corrosive._x = fixedX4;
              corrosive._y = fixedY4;
              feedback.text = "Try again!";
          }
          stopDrag();
      };

       

      //-------- end corrosive ------------------------

      //-------- Bring to Front Behavior --------------

       

      mx.behaviors.DepthControl.bringToFront(compressed);
      mx.behaviors.DepthControl.bringToFront(flammable);
      mx.behaviors.DepthControl.bringToFront(oxidizers);
      mx.behaviors.DepthControl.bringToFront(corrosive);

       

      //-------- End behavior -------------------------

       

      //========= end drag and drop  ========