I have a drog and drag exercice.
dict[box_a]=obj1_mc;
dict[box_b]=obj2_mc;
dict[box_c]=obj3_mc;
The obj I can drag them around and the box cant
function test_match(target,obj){
// if answer is good
if (dict[target]==obj) {
hits=hits+1;
textField.text=" Correct !!!";
obj.alpha=0.5;
// remove drag event
obj.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
obj.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
// quiz completed, all good
if (hits==max) {
textField.text="Congrats all good !!";
}
// if answer is bad
} else {
//if not good, still remove drag event
obj.alpha=0.5
obj.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
obj.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
textField.text="Incorrect";
}
//display the score so far
score_txt.text="your score is "+hits+" out of "+max;
}
This is my code. My problem is that if I take an object and put it ontop of another object(obj1_mc on obj3_mc) it will do like i put it onto the
wrong box. How could I fix this please
You need to check that the dopped-on object is one of the valid objects, and if it’s not – ignore the result. You should probably post a bit more code, since this only covers a small part of your functionality (the actual test).
EDIT:
Ok, so if you edit your mouseUp-handler to include a check to see if it’s dropped on ANY box;
That should work (untested).