# Drag n Drop Problem

**URL:** <https://forum.kirupa.com/t/drag-n-drop-problem/312202>\
**Category:** flash\
**Created:** [July 27, 2010, 11:17pm UTC](https://forum.kirupa.com/t/drag-n-drop-problem/312202 "2010-07-27T23:17:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alemieux34](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@alemieux34](https://forum.kirupa.com/u/alemieux34)\
**Post date:** [July 27, 2010, 11:17pm UTC](https://forum.kirupa.com/t/drag-n-drop-problem/312202/1 "2010-07-27T23:17:12Z")

</div>

I have the following code on 5 buttons. Each need to be dragged over a target and then acted on but only 1 of the buttons works. The other ones do not work. The functionality is the same, but the result is different when testing. As usual, when the button hits the target, something should happen, but if not, the button should spring back to its original location. Here’s the code for the one that works:

```auto
candy02.buttonMode = true;
candy02.addEventListener(MouseEvent.MOUSE_DOWN, alterState);
candy02.addEventListener(MouseEvent.MOUSE_UP, notIt);
function alterState(e:MouseEvent):void {
    e.target.startDrag();
    dragging = true;
    candy02.gotoAndPlay(5);
}
function notIt(e:MouseEvent):void {
    stopDrag();
    candy02.gotoAndStop(15);
    sc = donk.play();
    e.updateAfterEvent();
    if (candy02.hitTestObject(target1)) {
        trace("You hit the target");
        
        // MovieClip(this.root).gotoAndPlay("success");
        // candy01.removeEventListener(MouseEvent.CLICK, dontDrag);
        candy02.x = candy2X;
        candy02.y = candy2Y;
    } else {
        candy02.x = candy2X;
        candy02.y = candy2Y;
    }
}

```

Here’s the code for one that doesn’t work:

```auto
donut.buttonMode = true;
donut.addEventListener(MouseEvent.MOUSE_DOWN, breakState);
donut.addEventListener(MouseEvent.MOUSE_UP, alsoNot);
function breakState(e:MouseEvent):void {
    e.target.startDrag();
    dragging = true;
    donut.gotoAndPlay(5);
}
function alsoNot(e:MouseEvent):void {
    stopDrag();
    donut.gotoAndStop(15);
    sc = donk.play();
    e.updateAfterEvent();
    if (donut.hitTestObject(target1)) {
        trace("You hit the target");
        // MovieClip(this.root).gotoAndPlay("success");
        // candy01.removeEventListener(MouseEvent.CLICK, dontDrag);
        donut.x = donutX;
        donut.y = donutY;
    } else {
        donut.x = donutX;
        donut.y = donutY;
    }
}

```

I really need to resolve this by tonight. If anyone has suggestions, that would be great.

Thanks.
