[FMX04] Drag and Drop Help needed!

Hello everybody,

I’m trying to do some kind of test or quiz app that involves drag and drop with collision detection, I want to indicate valid candidate drop places during a drag and drop operation, for do that I change the opacity of the target rectangles.

The problem is that although the app detects all the collisions, just one of the drag rectangles makes the opacity of the drop rectangles change, the other drag rectangles don’t.

My code is based in one of the excellent Kirupa tutorials (connected Lines), here it is:

stop();

drag_mc = [“drag0”, “drag1”, “drag2”];
drop_mc = [“drop0”, “drop1”, “drop2”];

function init() {
numDrags = drag_mc.length;
for(var i:Number=0; i<numDrags; i++) {
var rect1:MovieClip = drag_mc*;
temp1 = eval(rect1);
temp1.ind = i;
temp1.onPress = function() {
this.startDrag();
};
temp1.onRelease = function() {
this.stopDrag();
};
temp1.onMouseMove = function() {
collision_detect(this);
};
} // fin del for principal
};

init();

function collision_detect(temp1) {
numDrops = drop_mc.length;
for(var j:Number=0; j<numDrops; j++) {
var rect2:MovieClip = drop_mc[j];
temp2 = eval(rect2);
if(temp1.hitTest(temp2)) {
temp2._alpha = 40;
trace(“drag” +temp1.ind+ " collisions with drop"+j);
}
else {
temp2._alpha = 100;
}
}
updateAfterEvent();
}

Any help or ideas?, thanks

  • I put my FLA if someone wants to check it