Skip to main content
Participant
November 3, 2008
Answered

Drag and Drop Item Sticking

  • November 3, 2008
  • 3 replies
  • 557 views
I'm creating a drag and drop game for grades K-2 and two of my pieces stick to the mouse when clicked. I'm not sure what the problem is as I've used the same code for all of my pieces.

The pants1_mc and the glasses_mc are the problems.

This topic has been closed for replies.
Correct answer pbesong
Tried your script and all of the items did the same thing - they stuck to the mouse on MOUSE_UP until I removed "true" from the line that says event.target.startDrag(true);
See if removing true helps for you.

3 replies

Inspiring
November 4, 2008
I think the problem might also be that you are listening for the Mouse Up on each of your draggable items. Instead you should register just one listener on the stage so that if the pointer isn't over your drag when you release it still will be able to "dropIt".

My guess would be that the pants and the glasses are a shape where when you stuck the pointer to the registration point (with the true inside the startDrag) the pointer wasn't actually over a pixel of the artwork. The other shapes weren't like that.

So removing the true might work for you here, but what if you wanted the true? Or what if you were going to constrain the dragging to a specific area and it was possible that the pointer would move off the artwork. You would have this problem again.

So I would add to the pickUp function:

addEventListener(MouseEvent.MOUSE_UP,dropIt);
event.target.startDrag()

Then inside the dropIt function

removeEventListener(MouseEvent.MOUSE_UP,dropIt);
stopDrag();

Finally you won't need each of the individual dropIt registrations in your main code.

almytonAuthor
Participant
November 4, 2008
Thank you so much!
pbesongCorrect answer
Inspiring
November 4, 2008
Tried your script and all of the items did the same thing - they stuck to the mouse on MOUSE_UP until I removed "true" from the line that says event.target.startDrag(true);
See if removing true helps for you.