6 Replies Latest reply on Apr 6, 2013 7:43 PM by Ned Murphy

    AS2 Drag and Drop - Completion Response

    xjanellexx

      I am making a drag and drop alphabet learning game. There are 27 Movie Clips (letters) in total that are able to be dragged.  I've made it so that 12 of the Movie Clips will drop in a specific DropZone, while the rest will just snap back to their original position.

       

      What I'd like to do is create a completion response that moves to a separate "Good Job!" screen when all 12 Movie Clips have been droped in the DropZone.  How can I do this?  I've searched online for some help but nothing seems to be particularly relevant.

       

      Thanks!

        • 1. Re: AS2 Drag and Drop - Completion Response
          Ned Murphy Adobe Community Professional & MVP

          Showing code ( preferably only relevant code ) can make it easier to help you.  In any case, just create a variable that you use to keep count of the 12 different drops, incrementing it each time it occurs.  When it reaches 12 you take whatever action you intend.  It sounds like all you want to do is use a gotoAndStop() command to send it to another frame where the "Good Job!" message appears

          1 person found this helpful
          • 2. Re: AS2 Drag and Drop - Completion Response
            xjanellexx Level 1

            Thanks for the input!  I'm actually brand new to Flash so the code I'm using is just copied from another source.  I have no idea if this is relevant or not, but this is what I have to work with.  Each of the twelve letters is on its own layer with this code in the layer (not on the item itself, if that makes a difference).

             

            food1_mc.onPress=function(){

            startDrag(this);

            }

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

            stopDrag();

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

            this.onTarget=true;

            _root.DropZone4.gotoAndStop(2);

            }else{

            this.onTarget=false;

            _root.DropZone4.gotoAndStop(1)

            }

            }

             

             

            food1_mc.myHomeX=food1_mc._x;

            food1_mc.myHomeY=food1_mc._y;

             

            food1_mc.onMouseDown=function(){

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

            mousePressed=true;

            }

            food1_mc.onMouseUp=function(){

            mousePressed=false;

            }

            food1_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;

            }

            }

             

            Does the variable you're talking about go directly into what I just pasted?  Do I put it on the items instead of the layers?  Can you give me some kind of template to fiddle with?  I understand gotoAndStop to some extent so I might be able to figure it out with a template, I'm just not sure how to go about counting, especially since the items don't have a specific place that they click into when they're correct, they're just able to be dropped anywhere in the DropZone (an image of a basket).

            • 3. Re: AS2 Drag and Drop - Completion Response
              Ned Murphy Adobe Community Professional & MVP

              Avoid putting code "on" items at all costs... you'll be learning a bad habit if you start doing that.

               

              What you could have would be something like what follows.  I don't know if this code relates to the 12 pieces you mention, but hopefully you can see the logic and apply it for them.

               

              var dropCount = 0;

               

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

                  stopDrag();

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

                          this.onTarget=true;

                          _root.DropZone4.gotoAndStop(2);

                         

                          dropCount += 1;  // add 1 to the dropCount

                          if(dropCount == 12){

                                gotoAndStop("goodjob");  // go to the frame labeled goodjob  

                          }

                  } else {

                          this.onTarget=false;

                          _root.DropZone4.gotoAndStop(1)

                  }

              }

              • 4. Re: AS2 Drag and Drop - Completion Response
                xjanellexx Level 1

                So I've tried adding this code but I still can't get the right result.

                 

                My first letter has this code:

                 

                food1_mc.onPress=function(){

                startDrag(this);

                }

                var dropCount = 0;

                 

                 

                 

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

                 

                    stopDrag();

                 

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

                 

                            this.onTarget=true;

                 

                            _root.DropZone4.gotoAndStop(2);

                 

                          

                 

                            dropCount += 1;  // add 1 to the dropCount

                 

                            if(dropCount == 12){

                 

                                  gotoAndStop("goodjob");  // go to the frame labeled goodjob 

                 

                            }

                 

                    } else {

                 

                            this.onTarget=false;

                 

                            _root.DropZone4.gotoAndStop(1)

                 

                    }

                 

                }

                 

                 

                food1_mc.myHomeX=food1_mc._x;

                food1_mc.myHomeY=food1_mc._y;

                 

                food1_mc.onMouseDown=function(){

                mousePressed=true;

                }

                food1_mc.onMouseUp=function(){

                mousePressed=false;

                }

                food1_mc.onEnterFrame=function(){

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

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

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

                }

                }

                 

                I've also added what you posted to the other 11 letters.  The first letter seems to work find but all other 11 have lost their ability to snap back into position or drop in the DropZone (they just stick to my mounse after I click on them).  Do I need to change the code for each letter somehow?  I've tried changing if(dropCount == 12){ to if(dropCount == 1){ to test if the one letter that's still dropping can activate the result, and it can't.  I've made sure the frame is named goodjob.  Thoughts?

                • 5. Re: AS2 Drag and Drop - Completion Response
                  xjanellexx Level 1

                  Nevermind!  I got it to work!  I had accidentally deleted part of the code on one object.  Thanks for the help.