6 Replies Latest reply on May 18, 2010 1:58 PM by kglad

    Drag and drop Query.

    vengod

      Hi all,

       

      i have this code for a drag and drop application.

       

      However, only mouth2_mc allows to be picked up and dropped - the others will only drop when another is selected? Hope this makes sense. How do i make them so they all allow me to drag AND drop.

       

      Thanks

       

       

      function pickupObject(event:MouseEvent):void{
      event.target.startDrag(true);
      }
      function dropObject(event:MouseEvent):void{
      event.target.stopDrag();
      }
      eye1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
      eye1_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
      eye2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
      eye2_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
      eye3_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
      eye3_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
      mouth1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
      mouth1_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
      mouth2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
      mouth2_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);

        • 1. Re: Drag and drop Query.
          kglad Adobe Community Professional & MVP

          use currentTarget instead of target.

          • 2. Re: Drag and drop Query.
            vengod Level 1

            Ok, so i changed each of the target words to say currentTarget and it

            hasnt affected the application?

             

            Code is now..

             

            function pickupObject(event:MouseEvent):void{
            event.currentTarget.startDrag(true);
            }
            function dropObject(event:MouseEvent):void{
            event.currentTarget.stopDrag();
            }
            eye1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
            eye1_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
            eye2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
            eye2_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
            eye3_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
            eye3_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
            mouth1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
            mouth1_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
            mouth2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
            mouth2_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);

             

            Thanks for trying though

            • 3. Re: Drag and drop Query.
              vengod Level 1

              This is still baffling me!

              • 4. Re: Drag and drop Query.
                kglad Adobe Community Professional & MVP

                then mouth2_mc is the only correct reference when your code executes (so, your other listener functions arent' being called).  to confirm, use the trace() function:

                 


                 

                 

                function pickupObject(event:MouseEvent):void{

                trace(event.currentTarget.name);
                event.target.startDrag(true);
                }
                function dropObject(event:MouseEvent):void{
                event.target.stopDrag();
                }
                eye1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
                eye1_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
                eye2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
                eye2_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
                eye3_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
                eye3_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
                mouth1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
                mouth1_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
                mouth2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
                mouth2_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);

                • 5. Re: Drag and drop Query.
                  vengod Level 1

                  Thanks,

                   

                  i used the trace function, when tested the movie each of the movie clips appeared correct in the output. However, i could only drop mouth 2, the rest of the parts wont be put down.

                   

                  Thanks.

                  • 6. Re: Drag and drop Query.
                    kglad Adobe Community Professional & MVP

                    check (using trace again) if you have some kind of depth issue so the mouseups are not being detected.