Skip to main content
Participant
September 27, 2010
Answered

Drag and Drop (simple)

  • September 27, 2010
  • 2 replies
  • 667 views

Hi guys

I'm trying to make a simple drag and drop game.  I've named the movie   clip in the properties window as "eye" and have written the following   code in the frame.

I can pick up the movie clip, but not put it down.  Can someone please help me?

I've attached the file: http://www.flashadvisor.com/forum/attachment.php?attachmentid=255&d=1285202999

Any help you can give to help me solve this will be much appreciated by me and a couple of hundred students i teach

Thanks

m

------------------------------------------------------------------------------------------------------------------------------------------------------------

AS3
eye.addEventListener(MouseEvent.MOUSE_DOWN, pick_up);
eye.addEventListener(MouseEvent.MOUSE_UP, put_down);



function pick_up(event:MouseEvent): void {
trace("pick up ");
event.target.startDrag(true);


}

function put_down (event:MouseEvent): void {
trace("downdowndowndown");
event.target.stopDrag();

}

eye.buttonMode = true;

------------------------------------------------------------------------------------------------------------------------------------------------------------

This topic has been closed for replies.
Correct answer

Andrea1's solution is correct.

Just you should use  startDrag()  -> without true parameter

2 replies

missymeeAuthor
Participant
September 27, 2010

sorry, attachment is here:

http://www.chsplayground.com/docs/drag_n_drop.zip

Correct answer
September 28, 2010

Andrea1's solution is correct.

Just you should use  startDrag()  -> without true parameter

missymeeAuthor
Participant
September 28, 2010

and hakan too, thank you

Inspiring
September 27, 2010

MOUSE_UP event listener should be added to stage - not the object:

eye.buttonMode = true;
eye.addEventListener(MouseEvent.MOUSE_DOWN, pick_up);


function pick_up(event:MouseEvent): void {
     trace("pick up ");
     event.target.startDrag(true);
     stage.addEventListener(MouseEvent.MOUSE_UP, put_down);
}

function put_down (event:MouseEvent): void {
     trace("downdowndowndown");
     stopDrag();
     stage.removeEventListener(MouseEvent.MOUSE_UP, put_down);
}

missymeeAuthor
Participant
September 28, 2010

thanks very much andrei!  i really appreciate it