What I’m trying to figure out is this: I have 5 card objects that can be dragged onto 3 target objects, and when the user is dragging a card over any target I would like to play an animation for that target (as a visual cue). The basic, stripped down code looks like this -
package {
public class Drag_and_Drop extends MovieClip {
private var activeCard_mc:MovieClip;
private var target_mc:MovieClip;
private var dragging:Boolean = false;
public function Drag_and_Drop() {
// Attach draggable cards to stage
for (var i:Number=numberOfCards; i>0; i--) {
activeCard_mc = new ActiveCard;
activeCard_mc.name = "activeCard_" + i;
activeCard_mc.mouseChildren = false;// Keep activeCard_mc textfield from interfering
addChild(activeCard_mc);
}
// Attach targets to stage
for (var n:Number=0; n<3; n++) {
target_mc = new Target;
target_mc.name = "target_" + (n + 1);
target_mc.addEventListener(Event.ENTER_FRAME, targetEnterFrame);
addChild(target_mc);
}
}
public function targetEnterFrame(event:Event) {
if (dragging) {
//trace(dragging);
if (target_mc.hitTestObject(activeCard_mc)) {
target_mc.gotoAndPlay(2);
}
} else {
//trace(dragging);
target_mc.gotoAndStop(1);
}
}
public function dragCard(event:MouseEvent):void {
dragging = true;
event.target.startDrag(false, rectangle);
event.target.parent.addChild(event.target);
}
public function stopDragCard(event:MouseEvent):void {
event.target.stopDrag();
dragging = false;
}
}
}
I’m not sure if the ENTER_FRAME listener is the best technique here. Also, the hitTest doesn’t seem to do anything (even though there’s no error):
target_mc.hitTestObject(activeCard_mc)