7 Replies Latest reply on Sep 3, 2013 8:30 AM by kglad

    AS2 Drag & Drop Game: How to reveal a 'congratulations' message

    Kid_Icarus Level 1

      Hi all.

       

      I'm nearing the end of a drag & drop game that contains 12 objects with 12 targets. I've pasted an example of how my drag & drop works. I'm trying to figure out how to display (or got to a frame) that displays a congratulations message with an 'If' (something that knows when all of my objects are all locked into the correct coordinates).

       

      Thanks in advance!

       

      Example of how drag & drop on on object/target is written

       

       

       

      // DRAG OBJECT NAME: 'drag4_mc' TARGET NAME 'drop_mc'

       

      drag4_mc.onPress = function() {

      startDrag(this);

      };

      drag4_mc.onRelease = drag4_mc.onReleaseOutside=function () {

      stopDrag();

      if (this._droptarget == "/drop_mc") {

      this.onTarget = true;

      _root.test1_mc.gotoAndStop(2);

      var isLocked = true;

      } else {

      this.onTarget = false;

      _root.drop_mc.gotoAndStop(1);

      }

      };

      //the variables below will store the clips starting position

      drag4_mc.myHomeX=drag4_mc._x;

      drag4_mc.myHomeY=drag4_mc._y;

      //the variables below will store the clips end position

      drag4_mc.myFinalX = 726.10;

      drag4_mc.myFinalY = 437.10;

      drag4_mc.onMouseDown = function() {

      //this variable tells us if the mouse is up or down

      mousePressed = true;

      };

      drag4_mc.onMouseUp = function() {

      mousePressed = false;

      };

      drag4_mc.onEnterFrame = function() {

      //all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

      // then move the MC back to its original starting point (with a smooth motion)"

      if (mousePressed == false && this.onTarget == false) {

      this._x -= (this._x-this.myHomeX)/5;

      this._y -= (this._y-this.myHomeY)/5;

      //if the object is dropped on any part of the target it slides to the center of the target

      } else if (mousePressed == false && this.onTarget == true) {

      this._x -= (this._x-this.myFinalX)/5;

      this._y -= (this._y-this.myFinalY)/5;

       

      }

      };

        • 1. Re: AS2 Drag & Drop Game: How to reveal a 'congratulations' message
          kglad Adobe Community Professional & MVP

          you can use:

           

          var correctDrops:Number = 0;

           

           

          // DRAG OBJECT NAME: 'drag4_mc' TARGET NAME 'drop_mc'

           

          drag4_mc.onPress = function() {

          startDrag(this);

          };

          drag4_mc.onRelease = drag4_mc.onReleaseOutside=function () {

          stopDrag();

          if (this._droptarget == "/drop_mc") {

          this.onTarget = true;

          _root.test1_mc.gotoAndStop(2);

          var isLocked = true;

          } else {

          this.onTarget = false;

          _root.drop_mc.gotoAndStop(1);

          }

          };

          //the variables below will store the clips starting position

          drag4_mc.myHomeX=drag4_mc._x;

          drag4_mc.myHomeY=drag4_mc._y;

          //the variables below will store the clips end position

          drag4_mc.myFinalX = 726.10;

          drag4_mc.myFinalY = 437.10;

          drag4_mc.onMouseDown = function() {

          //this variable tells us if the mouse is up or down

          mousePressed = true;

          };

          drag4_mc.onMouseUp = function() {

          mousePressed = false;

          };

          drag4_mc.onEnterFrame = function() {

          //all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

          // then move the MC back to its original starting point (with a smooth motion)"

          if (mousePressed == false && this.onTarget == false) {

          this._x -= (this._x-this.myHomeX)/5;

          this._y -= (this._y-this.myHomeY)/5;

          //if the object is dropped on any part of the target it slides to the center of the target

          } else if (mousePressed == false && this.onTarget == true) {

          correctDrops++;

          this._x -= (this._x-this.myFinalX)/5;

          this._y -= (this._y-this.myFinalY)/5;

          if(correctDrops==12){

          // do whatever

          }

          }

          };

          1 person found this helpful
          • 2. Re: AS2 Drag & Drop Game: How to reveal a 'congratulations' message
            Kid_Icarus Level 1

            Thanks, I can see the logic in that but just struggling to piece it together.  I'm coming back to Flash after a 8 year hiatus so I'm getting stuck at various stages. Sorry!

             

            would I have to write some script at the top that states that it's starting at zero correct drops... and then add your script amend to each button so that it can start counting accurately?

             

            Here is my entire script (brace yourself!). Any suggestions would be greatly appreciated.

             

             

             

            stop();

             

            drag1_mc.onPress = function() {

            startDrag(this);

            };

            drag1_mc.onRelease = drag1_mc.onReleaseOutside=function () {

            stopDrag();

            if (this._droptarget == "/drop1_mc") {

            this.onTarget = true;

            _root.drop1_mc.gotoAndStop(2);

            var isLocked = true;

            } else {

            this.onTarget = false;

            _root.drop1_mc.gotoAndStop(1);

            }

            };

            //the variables below will store the clips starting position

            drag1_mc.myHomeX=drag1_mc._x;

            drag1_mc.myHomeY=drag1_mc._y;

            //the variables below will store the clips end position

            drag1_mc.myFinalX = 304.30;

            drag1_mc.myFinalY = 437.65;

            drag1_mc.onMouseDown = function() {

            //this variable tells us if the mouse is up or down

            mousePressed = true;

            };

            drag1_mc.onMouseUp = function() {

            mousePressed = false;

            };

            drag1_mc.onEnterFrame = function() {

            //all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

            // then move the MC back to its original starting point (with a smooth motion)"

            if (mousePressed == false && this.onTarget == false) {

            this._x -= (this._x-this.myHomeX)/5;

            this._y -= (this._y-this.myHomeY)/5;

            //if the object is dropped on any part of the target it slides to the center of the target

            } else if (mousePressed == false && this.onTarget == true) {

            this._x -= (this._x-this.myFinalX)/5;

            this._y -= (this._y-this.myFinalY)/5;

             

            }

            };

             

             

            // PATIENT SUPPORT BUTTON

             

            drag6_mc.onPress = function() {

            startDrag(this);

            };

            drag6_mc.onRelease = drag6_mc.onReleaseOutside=function () {

            stopDrag();

            if (this._droptarget == "/drop66_mc") {

            this.onTarget = true;

            _root.drop66_mc.gotoAndStop(2);

            } else {

            this.onTarget = false;

            _root.drop66_mc.gotoAndStop(1);

            }

            };

            //the variables below will store the clips starting position

            drag6_mc.myHomeX=drag6_mc._x;

            drag6_mc.myHomeY=drag6_mc._y;

            //the variables below will store the clips end position

            drag6_mc.myFinalX = 161.45;

            drag6_mc.myFinalY = 437.65;

            drag6_mc.onMouseDown = function() {

            //this variable tells us if the mouse is up or down

            mousePressed = true;

            };

            drag6_mc.onMouseUp = function() {

            mousePressed = false;

            };

            drag6_mc.onEnterFrame = function() {

            //all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

            // then move the MC back to its original starting point (with a smooth motion)"

            if (mousePressed == false && this.onTarget == false) {

            this._x -= (this._x-this.myHomeX)/5;

            this._y -= (this._y-this.myHomeY)/5;

            //if the object is dropped on any part of the target it slides to the center of the target

            } else if (mousePressed == false && this.onTarget == true) {

            this._x -= (this._x-this.myFinalX)/5;

            this._y -= (this._y-this.myFinalY)/5;

             

            }

            };

             

            // CARER BUTTON

             

            drag2_mc.onPress = function() {

            startDrag(this);

            };

            drag2_mc.onRelease = drag2_mc.onReleaseOutside=function () {

            stopDrag();

            if (this._droptarget == "/drop22_mc") {

            this.onTarget = true;

            _root.drop22_mc.gotoAndStop(2);

            var isLocked = true;

            } else {

            this.onTarget = false;

            _root.drop22_mc.gotoAndStop(1);

            }

            };

            //the variables below will store the clips starting position

            drag2_mc.myHomeX=drag2_mc._x;

            drag2_mc.myHomeY=drag2_mc._y;

            //the variables below will store the clips end position

            drag2_mc.myFinalX = 446.05;

            drag2_mc.myFinalY = 438.10;

            drag2_mc.onMouseDown = function() {

            //this variable tells us if the mouse is up or down

            mousePressed = true;

            };

            drag2_mc.onMouseUp = function() {

            mousePressed = false;

            };

            drag2_mc.onEnterFrame = function() {

            //all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

            // then move the MC back to its original starting point (with a smooth motion)"

            if (mousePressed == false && this.onTarget == false) {

            this._x -= (this._x-this.myHomeX)/5;

            this._y -= (this._y-this.myHomeY)/5;

            //if the object is dropped on any part of the target it slides to the center of the target

            } else if (mousePressed == false && this.onTarget == true) {

            this._x -= (this._x-this.myFinalX)/5;

            this._y -= (this._y-this.myFinalY)/5;

             

            }

            };

             

            // CFUNDER BUTTON

             

            drag9_mc.onPress = function() {

            startDrag(this);

            };

            drag9_mc.onRelease = drag9_mc.onReleaseOutside=function () {

            stopDrag();

            if (this._droptarget == "/drop9_mc") {

            this.onTarget = true;

            _root.drop9_mc.gotoAndStop(2);

            var isLocked = true;

            } else {

            this.onTarget = false;

            _root.drop9_mc.gotoAndStop(1);

            }

            };

            //the variables below will store the clips starting position

            drag9_mc.myHomeX=drag9_mc._x;

            drag9_mc.myHomeY=drag9_mc._y;

            //the variables below will store the clips end position

            drag9_mc.myFinalX = 586.75;

            drag9_mc.myFinalY = 437.10;

            drag9_mc.onMouseDown = function() {

            //this variable tells us if the mouse is up or down

            mousePressed = true;

            };

            drag9_mc.onMouseUp = function() {

            mousePressed = false;

            };

            drag9_mc.onEnterFrame = function() {

            //all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

            // then move the MC back to its original starting point (with a smooth motion)"

            if (mousePressed == false && this.onTarget == false) {

            this._x -= (this._x-this.myHomeX)/5;

            this._y -= (this._y-this.myHomeY)/5;

            //if the object is dropped on any part of the target it slides to the center of the target

            } else if (mousePressed == false && this.onTarget == true) {

            this._x -= (this._x-this.myFinalX)/5;

            this._y -= (this._y-this.myFinalY)/5;

             

            }

            };

             

            // BIOTECH BUTTON

             

            drag12_mc.onPress = function() {

            startDrag(this);

            };

            drag12_mc.onRelease = drag12_mc.onReleaseOutside=function () {

            stopDrag();

            if (this._droptarget == "/biotech_mc") {

            this.onTarget = true;

            _root.biotech_mc.gotoAndStop(2);

            var isLocked = true;

            } else {

            this.onTarget = false;

            _root.biotech_mc.gotoAndStop(1);

            }

            };

            //the variables below will store the clips starting position

            drag12_mc.myHomeX=drag12_mc._x;

            drag12_mc.myHomeY=drag12_mc._y;

            //the variables below will store the clips end position

            drag12_mc.myFinalX = 866.95;

            drag12_mc.myFinalY = 437.10;

            drag12_mc.onMouseDown = function() {

            //this variable tells us if the mouse is up or down

            mousePressed = true;

            };

            drag12_mc.onMouseUp = function() {

            mousePressed = false;

            };

            drag12_mc.onEnterFrame = function() {

            //all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

            // then move the MC back to its original starting point (with a smooth motion)"

            if (mousePressed == false && this.onTarget == false) {

            this._x -= (this._x-this.myHomeX)/5;

            this._y -= (this._y-this.myHomeY)/5;

            //if the object is dropped on any part of the target it slides to the center of the target

            } else if (mousePressed == false && this.onTarget == true) {

            this._x -= (this._x-this.myFinalX)/5;

            this._y -= (this._y-this.myFinalY)/5;

             

            }

            };

             

            // Policy BUTTON

             

            drag11_mc.onPress = function() {

            startDrag(this);

            };

            drag11_mc.onRelease = drag11_mc.onReleaseOutside=function () {

            stopDrag();

            if (this._droptarget == "/policy_mc") {

            this.onTarget = true;

            _root.policy_mc.gotoAndStop(2);

            var isLocked = true;

            } else {

            this.onTarget = false;

            _root.policy_mc.gotoAndStop(1);

            }

            };

            //the variables below will store the clips starting position

            drag11_mc.myHomeX=drag11_mc._x;

            drag11_mc.myHomeY=drag11_mc._y;

            //the variables below will store the clips end position

            drag11_mc.myFinalX = 162.50;

            drag11_mc.myFinalY = 706.70;

            drag11_mc.onMouseDown = function() {

            //this variable tells us if the mouse is up or down

            mousePressed = true;

            };

            drag11_mc.onMouseUp = function() {

            mousePressed = false;

            };

            drag11_mc.onEnterFrame = function() {

            //all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

            // then move the MC back to its original starting point (with a smooth motion)"

            if (mousePressed == false && this.onTarget == false) {

            this._x -= (this._x-this.myHomeX)/5;

            this._y -= (this._y-this.myHomeY)/5;

            //if the object is dropped on any part of the target it slides to the center of the target

            } else if (mousePressed == false && this.onTarget == true) {

            this._x -= (this._x-this.myFinalX)/5;

            this._y -= (this._y-this.myFinalY)/5;

             

            }

            };

            // SCIENTIST BUTTON

             

            drag7_mc.onPress = function() {

            startDrag(this);

            };

            drag7_mc.onRelease = drag7_mc.onReleaseOutside=function () {

            stopDrag();

            if (this._droptarget == "/scientist_mc") {

            this.onTarget = true;

            _root.scientist_mc.gotoAndStop(2);

            var isLocked = true;

            } else {

            this.onTarget = false;

            _root.scientist_mc.gotoAndStop(1);

            }

            };

            //the variables below will store the clips starting position

            drag7_mc.myHomeX=drag7_mc._x;

            drag7_mc.myHomeY=drag7_mc._y;

            //the variables below will store the clips end position

            drag7_mc.myFinalX = 306.25;

            drag7_mc.myFinalY = 706.65;

            drag7_mc.onMouseDown = function() {

            //this variable tells us if the mouse is up or down

            mousePressed = true;

            };

            drag7_mc.onMouseUp = function() {

            mousePressed = false;

            };

            drag7_mc.onEnterFrame = function() {

            //all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

            // then move the MC back to its original starting point (with a smooth motion)"

            if (mousePressed == false && this.onTarget == false) {

            this._x -= (this._x-this.myHomeX)/5;

            this._y -= (this._y-this.myHomeY)/5;

            //if the object is dropped on any part of the target it slides to the center of the target

            } else if (mousePressed == false && this.onTarget == true) {

            this._x -= (this._x-this.myFinalX)/5;

            this._y -= (this._y-this.myFinalY)/5;

             

            }

            };

             

            // SCIENTIST BUTTON

             

            drag10_mc.onPress = function() {

            startDrag(this);

            };

            drag10_mc.onRelease = drag10_mc.onReleaseOutside=function () {

            stopDrag();

            if (this._droptarget == "/journalist_mc") {

            this.onTarget = true;

            _root.journalist_mc.gotoAndStop(2);

            var isLocked = true;

            } else {

            this.onTarget = false;

            _root.journalist_mc.gotoAndStop(1);

            }

            };

            //the variables below will store the clips starting position

            drag10_mc.myHomeX=drag10_mc._x;

            drag10_mc.myHomeY=drag10_mc._y;

            //the variables below will store the clips end position

            drag10_mc.myFinalX = 447.00;

            drag10_mc.myFinalY = 706.70;

            drag10_mc.onMouseDown = function() {

            //this variable tells us if the mouse is up or down

            mousePressed = true;

            };

            drag10_mc.onMouseUp = function() {

            mousePressed = false;

            };

            drag10_mc.onEnterFrame = function() {

            //all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

            // then move the MC back to its original starting point (with a smooth motion)"

            if (mousePressed == false && this.onTarget == false) {

            this._x -= (this._x-this.myHomeX)/5;

            this._y -= (this._y-this.myHomeY)/5;

            //if the object is dropped on any part of the target it slides to the center of the target

            } else if (mousePressed == false && this.onTarget == true) {

            this._x -= (this._x-this.myFinalX)/5;

            this._y -= (this._y-this.myFinalY)/5;

             

            }

            };

            // ETHICIST BUTTON

             

            drag8_mc.onPress = function() {

            startDrag(this);

            };

            drag8_mc.onRelease = drag8_mc.onReleaseOutside=function () {

            stopDrag();

            if (this._droptarget == "/ethic_mc") {

            this.onTarget = true;

            _root.ethic_mc.gotoAndStop(2);

            var isLocked = true;

            } else {

            this.onTarget = false;

            _root.ethic_mc.gotoAndStop(1);

            }

            };

            //the variables below will store the clips starting position

            drag8_mc.myHomeX=drag8_mc._x;

            drag8_mc.myHomeY=drag8_mc._y;

            //the variables below will store the clips end position

            drag8_mc.myFinalX = 586.15;

            drag8_mc.myFinalY = 706.65;

            drag8_mc.onMouseDown = function() {

            //this variable tells us if the mouse is up or down

            mousePressed = true;

            };

            drag8_mc.onMouseUp = function() {

            mousePressed = false;

            };

            drag8_mc.onEnterFrame = function() {

            //all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

            // then move the MC back to its original starting point (with a smooth motion)"

            if (mousePressed == false && this.onTarget == false) {

            this._x -= (this._x-this.myHomeX)/5;

            this._y -= (this._y-this.myHomeY)/5;

            //if the object is dropped on any part of the target it slides to the center of the target

            } else if (mousePressed == false && this.onTarget == true) {

            this._x -= (this._x-this.myFinalX)/5;

            this._y -= (this._y-this.myFinalY)/5;

             

            }

            };

             

            // PATIENT BUTTON

             

            drag3_mc.onPress = function() {

            startDrag(this);

            };

            drag3_mc.onRelease = drag3_mc.onReleaseOutside=function () {

            stopDrag();

            if (this._droptarget == "/patient_mc") {

            this.onTarget = true;

            _root.patient_mc.gotoAndStop(2);

            var isLocked = true;

            } else {

            this.onTarget = false;

            _root.patient_mc.gotoAndStop(1);

            }

            };

            //the variables below will store the clips starting position

            drag3_mc.myHomeX=drag3_mc._x;

            drag3_mc.myHomeY=drag3_mc._y;

            //the variables below will store the clips end position

            drag3_mc.myFinalX = 727.00;

            drag3_mc.myFinalY = 706.65;

            drag3_mc.onMouseDown = function() {

            //this variable tells us if the mouse is up or down

            mousePressed = true;

            };

            drag3_mc.onMouseUp = function() {

            mousePressed = false;

            };

            drag3_mc.onEnterFrame = function() {

            //all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

            // then move the MC back to its original starting point (with a smooth motion)"

            if (mousePressed == false && this.onTarget == false) {

            this._x -= (this._x-this.myHomeX)/5;

            this._y -= (this._y-this.myHomeY)/5;

            //if the object is dropped on any part of the target it slides to the center of the target

            } else if (mousePressed == false && this.onTarget == true) {

            this._x -= (this._x-this.myFinalX)/5;

            this._y -= (this._y-this.myFinalY)/5;

             

            }

            };

             

             

            // RESEARCH NURSE BUTTON

             

            dragfive_mc.onPress = function() {

            startDrag(this);

            };

            dragfive_mc.onRelease = dragfive_mc.onReleaseOutside=function () {

            stopDrag();

            if (this._droptarget == "/research_mc") {

            this.onTarget = true;

            _root.research_mc.gotoAndStop(2);

            var isLocked = true;

            } else {

            this.onTarget = false;

            _root.research_mc.gotoAndStop(1);

            }

            };

            //the variables below will store the clips starting position

            dragfive_mc.myHomeX=dragfive_mc._x;

            dragfive_mc.myHomeY=dragfive_mc._y;

            //the variables below will store the clips end position

            dragfive_mc.myFinalX = 865.80;

            dragfive_mc.myFinalY = 706.70;

            dragfive_mc.onMouseDown = function() {

            //this variable tells us if the mouse is up or down

            mousePressed = true;

            };

            dragfive_mc.onMouseUp = function() {

            mousePressed = false;

            };

            dragfive_mc.onEnterFrame = function() {

            //all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

            // then move the MC back to its original starting point (with a smooth motion)"

            if (mousePressed == false && this.onTarget == false) {

            this._x -= (this._x-this.myHomeX)/5;

            this._y -= (this._y-this.myHomeY)/5;

            //if the object is dropped on any part of the target it slides to the center of the target

            } else if (mousePressed == false && this.onTarget == true) {

            this._x -= (this._x-this.myFinalX)/5;

            this._y -= (this._y-this.myFinalY)/5;

             

            }

            };

            // CLINICIAN 2 (TEMP NAME) BUTTON

             

            drag4_mc.onPress = function() {

            startDrag(this);

            };

            drag4_mc.onRelease = drag4_mc.onReleaseOutside=function () {

            stopDrag();

            if (this._droptarget == "/test1_mc") {

            this.onTarget = true;

            _root.test1_mc.gotoAndStop(2);

            var isLocked = true;

            } else {

            this.onTarget = false;

            _root.test1_mc.gotoAndStop(1);

            }

            };

            //the variables below will store the clips starting position

            drag4_mc.myHomeX=drag4_mc._x;

            drag4_mc.myHomeY=drag4_mc._y;

            //the variables below will store the clips end position

            drag4_mc.myFinalX = 726.10;

            drag4_mc.myFinalY = 437.10;

            drag4_mc.onMouseDown = function() {

            //this variable tells us if the mouse is up or down

            mousePressed = true;

            };

            drag4_mc.onMouseUp = function() {

            mousePressed = false;

            };

            drag4_mc.onEnterFrame = function() {

            //all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

            // then move the MC back to its original starting point (with a smooth motion)"

            if (mousePressed == false && this.onTarget == false) {

            this._x -= (this._x-this.myHomeX)/5;

            this._y -= (this._y-this.myHomeY)/5;

            //if the object is dropped on any part of the target it slides to the center of the target

            } else if (mousePressed == false && this.onTarget == true) {

            this._x -= (this._x-this.myFinalX)/5;

            this._y -= (this._y-this.myFinalY)/5;

            }

            };

            • 3. Re: AS2 Drag & Drop Game: How to reveal a 'congratulations' message
              kglad Adobe Community Professional & MVP

              yes, i have that listed in the first line of code.  and you can condense your code so it's easier to read and debug.

               

              var correctDrops:Number = 0;

              import fl.transitions.Tween;

              import fl.transitions.easing.Strong;

               

              var drag_mcA:Array = [drag1_mc,drag2_mc, etc];

              var drop_targetA:Array = ["/drop1_mc", "/drop2_mc", etc];

              var tweenX:Tween;

              var tweenY:Tween;

              var tweenTime:Number = 1;

               

              for(var i:Number=0;i<drag_mcA.length;i++){

                  drag_mcA[i].ivar = i;

                  drag_mcA[i].myHomeX = drag_mcA[i]._x;

                  drag_mcA[i].myHomeY = drag_mcA[i]._y;

                  drag_mcA[i].onPress=function(){

                      this.startDrag();

                  }

                  drag_mcA[i].onRelease=drag_mcA[i].onReleaseOutside=function(){

                      this.stopDrag();

                      if(this._droptarget==drop_targetA[this.ivar]){

                          correctDrops++;

                          completeCheckF();

                          tweenX = new Tween(this, "x", Strong.easeOut, this._x, eval(drop_targetA[this.ivar])._x, tweenTime, true);

                          tweenY = new Tween(this, "y", Strong.easeOut, this._y, eval(drop_targetA[this.ivar])._y, tweenTime, true);

                          delete this.onPress;

                          delete this.onRelease;

                          delete this.onReleaseOutside;

                      } else {

                          tweenX = new Tween(this, "x", Strong.easeOut, this._x, this.myHomeX, tweenTime, true);

                          tweenY = new Tween(this, "y", Strong.easeOut, this._y, this.myHomeY, tweenTime, true);

                      }

                  }

              }

              function completeCheckF(){

                  if(correctDrops==drag_mcA.length){

                      // do whatever

                  }

              }

               

              1 person found this helpful
              • 4. Re: AS2 Drag & Drop Game: How to reveal a 'congratulations' message
                Kid_Icarus Level 1

                Hmm, I've added the drag and drop names to the script and have tried using the above code but I can't seem to get anything to work now

                • 5. Re: AS2 Drag & Drop Game: How to reveal a 'congratulations' message
                  kglad Adobe Community Professional & MVP

                  copy and paste the code you used.

                  • 6. Re: AS2 Drag & Drop Game: How to reveal a 'congratulations' message
                    Kid_Icarus Level 1

                    I also added some text to reveal when the answers are correct but I haven't got the chance to debug it yet..

                    stop();

                     

                    txt_correct_mc._alpha = 0;

                     

                    var correctDrops:Number = 0;

                     

                    import fl.transitions.Tween;

                     

                    import fl.transitions.easing.Strong;

                     

                     

                     

                    var drag_mcA:Array = [drag1_mc,drag2_mc,drag3_mc,drag4_mc,dragfive_mc,drag6_mc,drag7_mc,drag8_mc,drag9_mc,drag 10_mc,drag11_mc,drag12_mc];

                     

                    var drop_targetA:Array = ["/drop1_mc", "/drop22_mc","/drop66_mc","/drop9_mc", "/test1_mc","/biotech_mc","/policy_mc","/scientist_mc","/journalist_mc","/ethic_mc","/pat ient_mc","/research_mc"];

                     

                    var tweenX:Tween;

                     

                    var tweenY:Tween;

                     

                    var tweenTime:Number = 1;

                     

                     

                     

                    for(var i:Number=0;i<drag_mcA.length;i++){

                     

                        drag_mcA[i].ivar = i;

                     

                        drag_mcA[i].myHomeX = drag_mcA[i]._x;

                     

                        drag_mcA[i].myHomeY = drag_mcA[i]._y;

                     

                        drag_mcA[i].onPress=function(){

                     

                            this.startDrag();

                     

                        }

                     

                        drag_mcA[i].onRelease=drag_mcA[i].onReleaseOutside=function(){

                     

                            this.stopDrag();

                     

                            if(this._droptarget==drop_targetA[this.ivar]){

                     

                                correctDrops++;

                     

                                completeCheckF();

                     

                                tweenX = new Tween(this, "x", Strong.easeOut, this._x, eval(drop_targetA[this.ivar])._x, tweenTime, true);

                     

                                tweenY = new Tween(this, "y", Strong.easeOut, this._y, eval(drop_targetA[this.ivar])._y, tweenTime, true);

                     

                                delete this.onPress;

                     

                                delete this.onRelease;

                     

                                delete this.onReleaseOutside;

                     

                            } else {

                     

                                tweenX = new Tween(this, "x", Strong.easeOut, this._x, this.myHomeX, tweenTime, true);

                     

                                tweenY = new Tween(this, "y", Strong.easeOut, this._y, this.myHomeY, tweenTime, true);

                     

                            }

                     

                        }

                     

                    }

                     

                    function completeCheckF(){

                     

                        if(correctDrops==drag_mcA.length){

                           

                            txt_correct_mc._alpha = 100;

                     

                    }

                    • 7. Re: AS2 Drag & Drop Game: How to reveal a 'congratulations' message
                      kglad Adobe Community Professional & MVP

                      copy and paste the trace output after using the following and trying a drag drag1_mc:

                       

                       

                      stop();

                       

                      txt_correct_mc._alpha = 0;

                       

                      var correctDrops:Number = 0;

                       

                      import fl.transitions.Tween;

                       

                      import fl.transitions.easing.Strong;

                       

                       

                       

                      var drag_mcA:Array = [drag1_mc,drag2_mc,drag3_mc,drag4_mc,dragfive_mc,drag6_mc,drag7_mc,dr ag8_mc,drag9_mc,drag10_mc,drag11_mc,drag12_mc];

                       

                      var drop_targetA:Array = ["/drop1_mc", "/drop22_mc","/drop66_mc","/drop9_mc", "/test1_mc","/biotech_mc","/policy_mc","/scientist_mc","/journalist_m c","/ethic_mc","/patient_mc","/research_mc"];

                       

                      var tweenX:Tween;

                       

                      var tweenY:Tween;

                       

                      var tweenTime:Number = 1;

                       

                       

                       

                      for(var i:Number=0;i<drag_mcA.length;i++){

                       

                          drag_mcA[i].ivar = i;

                       

                          drag_mcA[i].myHomeX = drag_mcA[i]._x;

                       

                          drag_mcA[i].myHomeY = drag_mcA[i]._y;

                      trace(drag_mcA[i]);

                          drag_mcA[i].onPress=function(){

                      trace(this);

                              this.startDrag();

                       

                          }

                       

                          drag_mcA[i].onRelease=drag_mcA[i].onReleaseOutside=function(){

                       

                              this.stopDrag();

                       

                              if(this._droptarget==drop_targetA[this.ivar]){

                       

                                  correctDrops++;

                       

                                  completeCheckF();

                       

                                  tweenX = new Tween(this, "x", Strong.easeOut, this._x, eval(drop_targetA[this.ivar])._x, tweenTime, true);

                       

                                  tweenY = new Tween(this, "y", Strong.easeOut, this._y, eval(drop_targetA[this.ivar])._y, tweenTime, true);

                       

                                  delete this.onPress;

                       

                                  delete this.onRelease;

                       

                                  delete this.onReleaseOutside;

                       

                              } else {

                       

                                  tweenX = new Tween(this, "x", Strong.easeOut, this._x, this.myHomeX, tweenTime, true);

                       

                                  tweenY = new Tween(this, "y", Strong.easeOut, this._y, this.myHomeY, tweenTime, true);

                       

                              }

                       

                          }

                       

                      }

                       

                      function completeCheckF(){

                       

                          if(correctDrops==drag_mcA.length){

                             

                              txt_correct_mc._alpha = 100;

                       

                      }

                      1 person found this helpful