# Drag and Drop

**URL:** <https://forum.kirupa.com/t/drag-and-drop/227782>\
**Category:** Uncategorized\
**Created:** [June 2, 2007, 2:55am UTC](https://forum.kirupa.com/t/drag-and-drop/227782 "2007-06-02T02:55:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)\
**Post date:** [June 2, 2007, 2:55am UTC](https://forum.kirupa.com/t/drag-and-drop/227782/1 "2007-06-02T02:55:41Z")

</div>

I have some glitches in some drag and drop code I’m working with. I’ve modified someone else’s code to get the effect I need. The issue is with the following function:

myAnswers = [[1, 1], [2, 4], [3, 2], [1, 3], [3, 6], [1, 5]];  
function doDrop(cardNum, categoryNum) {  
for (i=1; i\<7; i++) {  
Q = \_root.myAnswers[i-1][0];  
A = \_root.myAnswers[i-1][1];  
//trace(Q+","+A);  
if (\_root[“a”+A].hitTest("\_root.q"+Q)) {  
//trace(\_root[“a”+A].hitTest("\_root.q"+Q));  
\_root.results\_txt.text = “Correct”;  
\_root[“a”+A].\_x = \_root[“q”+Q].\_x+15;  
\_root[“a”+A].\_y = \_root[“q”+Q].\_y+15;  
\_root[“a”+A].enabled = false;  
} else {  
//trace(\_root[“a”+A].hitTest("\_root.q"+Q));  
\_root.results\_txt.text = “Wrong”;  
\_root[“a”+A].enabled = true;  
\_root[“a”+A].\_x = \_root[“a”+A].stx;  
\_root[“a”+A].\_y = \_root[“a”+A].sty;  
}  
}  
}

The array “myAnswers” tells which card goes to which category. But since I’m using a loop to access the array I don’t get the appropriate “correct” or “wrong” text displayed - the last item in the list is always displayed instead (and that is “wrong” until you get to the second to last card for some reason - shouldn’t it be the last card?). I could use some help fixing this function.

The test file is here:  
[http://www.tornedgedesign.com/\_test/kirupa/drag\_drop.zip](http://www.tornedgedesign.com/_test/kirupa/drag_drop.zip)
