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:
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:
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.