5 Replies Latest reply on Aug 11, 2010 4:56 PM by kglad

    Drag and Drop problem

    Shad0wdrag0n

      I have several buttons within a container MC. What I want is to have it so that when a button is clicked on a particular MC is attached to the cursor (startDrag) and the container MC is moved to the side. The code below seems to work well for the attaching and moving part, but I can't figure out how to detach the MC from the cursor. I've tried numerous variations of stopDrag and removeMovieClip in a variety of areas (inside the container MC, inside the dragged MC, on the main timeline, etc), but nothing seems to work. Basically, what I want is that when the mouse is clicked again on a particular MC on a particular frame it checks to see if the two MCs overlap. If they do it advances the main timeline to the next frame. If they don't the dragged MC is simply removed and nothing else happens. So, any ideas for how to do this?

       

      this.onRelease=function(){

          attachMovie("keys", "keys", this.getNextHighestDepth())

          startDrag(keys, true)

          _root.inventory._x=780;

      }

        • 1. Re: Drag and Drop problem
          kglad Adobe Community Professional & MVP

          stopDrag() will always cause the currently dragged movieclip to stop being dragged.  your problem may be that you can't click on anything with the mouse while you're dragging a movieclip because that movieclip is intercepting mouse events.  to remedy, use swapDepths().

          • 2. Re: Drag and Drop problem
            Shad0wdrag0n Level 1

            How would I use swapDepths? What would I swap the dragged MC with? Is there a way to make a generic stopDrag function so that if the mouse is clicked anywhere it activates the stopDrag function? One of the things I tried was putting the below code on the first frame of the MC being dragged, but it didn't work.

             

            this.onRelease=function(){

              stopDrag();

            }

            • 3. Re: Drag and Drop problem
              kglad Adobe Community Professional & MVP

              that will work, too.  if you want to stop dragging when the mouse is up, use:

               

               

              this.onMouseUp=function(){

              stopDrag();

              }

              • 4. Re: Drag and Drop problem
                Shad0wdrag0n Level 1

                That seems to work if I change the first code from onRelease to onPress. That way you have to click and hold to drag the object, then release to drop it. Is there a way to make it work with onRelease in the first code? So the player clicks and releases to startDrag, then clicks and releases a second time to stopDrag? With the ways I've tried it it's like the second click isn't being recognised or something.

                • 5. Re: Drag and Drop problem
                  kglad Adobe Community Professional & MVP

                  :

                   

                  whateverobject.onRelease=function(){

                  this.onMouseUp=function(){

                  stopDrag();

                  delete this.onMouseUp;

                  }

                  whatever.startDrag();

                  }

                   

                  p.s.  please mark this thread as answered, if you can.