Skip to main content
Participating Frequently
September 3, 2010
Answered

How to drag & drop a movie clip with a button in it

  • September 3, 2010
  • 2 replies
  • 1995 views

Hello!

I'm very much a beginner in ActionScript so please be gentle!

I've got a movie clip that I want to be able to drag and drop on stage, I've added this code to do this:

correct1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp1);

correct1_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt1);


function pickUp1(event:MouseEvent):void {

    event.target.startDrag();

}

function dropIt1(event:MouseEvent):void {

    event.target.stopDrag();

}

correct1_mc.buttonMode = false;

But because theres a button in it, once you click the button it comes up with this error:

ReferenceError: Error #1069: Property startDrag not found on flash.display.SimpleButton and there is no default value.

at SpeedCameraGame_fla::MainTimeline/pickUp1()

ReferenceError: Error #1069: Property stopDrag not found on flash.display.SimpleButton and there is no default value.

at SpeedCameraGame_fla::MainTimeline/dropIt1()

But the button still does what its supposed to do...but I fear I shouldn't have these errors coming up anyway as (knowing me) I'll run into trouble later on because of it...

I would of thought as long as the button is within the movie clip there wouldn't be a problem dragging it about and such...

Any help would be appreciated!

This topic has been closed for replies.
Correct answer Ned Murphy

instead of using target, try using currentTarget...

event.currentTarget.startDrag();

event.currentTarget.stopDrag();

2 replies

Ned Murphy
Ned MurphyCorrect answer
Legend
September 3, 2010

instead of using target, try using currentTarget...

event.currentTarget.startDrag();

event.currentTarget.stopDrag();

September 3, 2010

Try replacing event.target with event.currentTarget in your two functions - that should make the parent the target. Also, relying on a mouseUp on correct1_mc will get you into trouble. It's pretty easy to drag quickly so the mouse is off the object and let go... and the object becomes stuck to the mouse until you click and release. The better option is to place a mouseUp listener on the stage when you begin your startDrag and then a mouseUp anywhere will stop dragging.

McFlibbleAuthor
Participating Frequently
September 3, 2010

Hi, thanks! The currentTarget did the trick!

Thanks for the added tip there, I'm assuming it would be this code:

stage.addEventListener(MouseEvent.MOUSE_UP, function1);

Is this right? I'm not exactly sure what I'd put in the function though...or where to put it!

Sorry to be asking dense questions! :S