# Drag and drop with multiple targets problem

**URL:** <https://forum.kirupa.com/t/drag-and-drop-with-multiple-targets-problem/212866>\
**Category:** Uncategorized\
**Created:** [January 15, 2007, 6:33am UTC](https://forum.kirupa.com/t/drag-and-drop-with-multiple-targets-problem/212866 "2007-01-15T06:33:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![coche](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@coche](https://forum.kirupa.com/u/coche)\
**Post date:** [January 15, 2007, 6:33am UTC](https://forum.kirupa.com/t/drag-and-drop-with-multiple-targets-problem/212866/1 "2007-01-15T06:33:58Z")

</div>

Hey this is my first post!!, thanks to everybody for this great forum, your help and knowledge makes Flash not so hard.

Well I’m trying to do some kind of quiz (like the one’s included in Flash templates), the basic functionality is drag one item and put it in the correct place (or drop place). I take some code of the kirupa’s collision tutorials, but I can’t apply that to my particular situation.

The current situation is: i have 3 drag rectangles and 3 drop rectangles, I can drag and drop all the drag rectangles, but just the last one (the third drag rectangle), seems to sense the collision with all the 3 drop rectangles.

My code is:

[FONT=Courier New]drag\_mc = [“drag0”, “drag1”, “drag2”];  
drop\_mc = [“drop0”, “drop1”, “drop2”];

**function** init() {  
numDrags = drag\_mc. **length** ;  
**for** (i=0; i\<numDrags; i++) {  
**var** rect1: **MovieClip** = drag\_mc\*;  
temp1 = **eval** (rect1);  
temp1. **onPress** = **function** () {  
**this**. **startDrag** ();  
drop = false;  
};  
temp1. **onRelease** = **function** () {  
**this**. **stopDrag** ();  
drop = true;  
};  
} // fin del for principal  
**this**. **onMouseMove** = **function** () {  
collision\_detect(“temp1”);  
};  
};

init();

**function** collision\_detect(rect) {  
numDrops = drop\_mc. **length** ;  
**for** (j=0; j\<numDrops; j++) {  
var rect2: **MovieClip** = drop\_mc[j];  
temp2 = **eval** (rect2);  
temp1 = **eval** (rect);

```
    **if** (temp1. **hitTest** (temp2)) {
        **trace** ("collision");
        temp2. **_alpha** = 40;
    }
    **else** {
        temp2. **_alpha** = 100;
    }
    **updateAfterEvent** ();
}

```

}

Thanks in advance:nat:[/FONT]
