here is the full code for the hitTest checking
function item_onMouseDown(event:MouseEvent):void {
currentClip = MovieClip(event.currentTarget);
startX = currentClip.x;
startY = currentClip.y;
addChild(currentClip); //bring to the front
currentClip.startDrag();
stage.addEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
}
function stage_onMouseUp(event:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
currentClip.stopDrag();
var index:int = dragArray.indexOf(currentClip);
var matchClip:MovieClip = MovieClip(matchArray[index]);
if(currentClip.hitTestObject(matchClip)) {
currentClip.x = matchClip.x;
currentClip.y = matchClip.y;
currentClip.removeEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
currentClip.buttonMode = false;
if (currentClip.hitTestObject(pink_target))
{
score += 1;
right.play();
pink_not.mouseEnabled = false;
}
else if (currentClip.hitTestObject(pink_target))
{
score -= 1;
wrong.play();
pink_harm.mouseEnabled = false;
}
else if (blue_non.hitTestObject(blue_target))
{
score += 1;
right.play();
blue_flam.mouseEnabled = false;
}
else if (blue_flam.hitTestObject(blue_target))
{
score -= 1;
wrong.play();
blue_non.mouseEnabled = false;
}
if (score < 0) score = 0;
ScoreDisplay.text = String(score);
}
else {
currentClip.x = startX;
currentClip.y = startY;
}
}
so i should use the currentClip instead of the button itself?
You should know better than anyone what you need to be using, I can only suggest based on thinking I know what you are trying to do.
In the code you show you are using the currentClip for part of it and not for the rest. I think what you want to do in to determine if the currentClip is the pink or the blue, and for whichever it is, test the rest of the conditions. That way you are not testing an object that has not just been dropped.
if(currentClip == pink_harm && pink_harm.hitTestObject(pink_target)) {
score += 1;
right.play();
pink_not.mouseEnabled = false;
} else if (currentClip == pink_not && pink_not.hitTestObject(pink_target)) { score -= 1;
wrong.play();
pink_harm.mouseEnabled = false;
} else if(currentClip == blue...etc....