4 Replies Latest reply on Mar 27, 2010 4:55 AM by Ned Murphy

    drag and drop help

    DavidKinmond

      I Have the drag and drop working where you drag a text movieclip onto a picture of an object movieclip but having some problems. I know its something to do with the hitTest function but when i drop the word "cow" onto the picture of a dog it actually says this is correct by  displaying the word cow above the picture of the dog when instead it shouldnt allow me to  drop the text onto the picture which doesnt match.

       

      Basically i need to know how to seperate the drag hitTest function for the DogPic/DogText so that it has its own function to detect a hit. At the moment you can see in the below code I have 1 hittest fucntion detecting both collisions when they need seperate functions

       

      I tried making a seperate function for each but it didnt work

       

       

       

       

      function checkTarget(drag)
      {   
          if (drag.hitTest(CowPic))
          {
              CowText.stopDrag();
              CowText.onPress = function()
              {
                 
              }
             
              CowText._x = CowPic._x - 14;
              CowText._y = CowPic._y + 64;
             
      }
         
          else if (drag.hitTest(DogPic))
         
          {
              DogText.stopDrag();
              DogText.onPress = function()
              {
                 
              }
                     
              DogText._x = DogPic._x - 15;
              DogText._y = DogPic._y - 79;
          }
        
         
      }

       

       

      this is full code here

       

       

      onMouseMove = function () {
          updateAfterEvent();
      }

      CowText.onPress = function() {
          startDrag(CowText, true, 100, 75, 450, 325);
      }

      DogText.onPress = function() {
          startDrag(DogText, true, 100, 75, 450, 325);
      }


      CowText.onRelease = function() {
          this.stopDrag();
          checkTarget(this);
      }

      DogText.onRelease = function() {
          this.stopDrag();
          checkTarget(this);
      }

      CowText.onReleaseOutside = function() {
          this.stopDrag();
          checkTarget(this);
      }

      DogText.onReleaseOutside = function() {
          this.stopDrag();
          checkTarget(this);
      }
      function checkTarget(drag)
      {   
          if (drag.hitTest(CowPic))
          {
              CowText.stopDrag();
              CowText.onPress = function()
              {
                 
              }
             
              CowText._x = CowPic._x - 14;
              CowText._y = CowPic._y + 64;
             
      }
         
          else if (drag.hitTest(DogPic))
         
          {
              DogText.stopDrag();
              DogText.onPress = function()
              {
                 
              }
                     
              DogText._x = DogPic._x - 15;
              DogText._y = DogPic._y - 79;
          }
        
         
      }









        • 1. Re: drag and drop help
          Ned Murphy Adobe Community Professional & MVP

          If you want to separate the two so that they have their own check function, just use the existing onRelease functions...

           

          CowText.onRelease = CowText.onReleaseOutside = function() {
              stopDrag();
              if CowText.hitTest(CowPic))
              {
                  // etc...       
               }

          }

          1 person found this helpful
          • 2. Re: drag and drop help
            kglad Adobe Community Professional & MVP

            try:

             


             

             

             

             



            CowText.onPress = function() {
                startDrag(CowText, true, 100, 75, 450, 325);
            }

            DogText.onPress = function() {
                startDrag(DogText, true, 100, 75, 450, 325);
            }


            CowText.onRelease ==CowText.onReleaseOutside function() {
                this.stopDrag();

            dropTarget=CowPic
                checkTarget(this);
            }

            DogText.onRelease=DogText.onReleaseOutside = function() {
                this.stopDrag();

            dropTarget=DogPic;
                checkTarget(this);
            }

            function checkTarget(drag)
            {   
                if (eval(drag._droptarget)==drag.dropTarget)
            {
            //do whatever.  correct drop target

            }   else {

            //do whatever else.  incorrect drop target

            }   
            }








            1 person found this helpful
            • 3. Re: drag and drop help
              DavidKinmond Level 1

              thanks for the help its working fine now

              • 4. Re: drag and drop help
                Ned Murphy Adobe Community Professional & MVP

                You're welcome