Some Basic Stuff (I think)

Sup dawgs

I’m pretty new to AS3 still (I’ve made some simple applications in the past, but I’m still grasping at the logic) and I’m currently working on a simple game where one can drag christmas balls into a christmas tree. I’ve already managed to make the christmas ball dragable, but what I’m currently trying to achieve is for the ball to snap into place and become undraggable when it reaches the destined spot in the christmas tree (which will be indicated by a sparkly graphic or an arrow, depends what I decide on later)

This is where I’m not sure how to proceed. I’ve managed to get another piece of code from a tutorial where it says that once the location of the ball and the location of the indicator (the drag target) match, the ball becomes undraggable.

Here’s what I’ve got right now


ball1.addEventListener(MouseEvent.MOUSE_DOWN, dragFn);
function dragFn(event:MouseEvent){

    event.target.startDrag();
}

ball1.addEventListener(MouseEvent.MOUSE_UP, dropFn);
function dropFn(event:MouseEvent){

    event.target.stopDrag();
    var target1 = "target" + event.target.name;

if (event.target.dropTarget != null && event.target.dropTarget.parent == target1){
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, dragFn);
event.target.removeEventListener(MouseEvent.MOUSE_UP, dropFn);
event.target.buttonMode = false;
event.target.x = target1.x;
event.target.y = target1.y;

} else {
trace (“Derp”)
}
}

ball1.buttonMode = true;


However, when I test the program nothing happens (well, it just traces “Derp” all the time) when I place the the ball on top of the indicator, probably because its practically impossible (as far as my knowledge goes) to get the ball to exactly match the destination’s x and y. What would really help me out would be a bit of code that causes the ball to be snapped into place when it’s dropped at the indicator. Any help on this would be very much appreciated.

Thanks in advance