# hitTest on multiple objects in nested for loop

**URL:** https://forum.kirupa.com/t/hittest-on-multiple-objects-in-nested-for-loop/271747
**Category:** flash
**Created:** [September 27, 2008, 5:40pm UTC](https://forum.kirupa.com/t/hittest-on-multiple-objects-in-nested-for-loop/271747 "2008-09-27T17:40:21Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ryan4294](https://avatars.discourse-cdn.com/v4/letter/r/e19b73/32.png) [@ryan4294](https://forum.kirupa.com/u/ryan4294)
#### Post date: [September 27, 2008, 5:40pm UTC](https://forum.kirupa.com/t/hittest-on-multiple-objects-in-nested-for-loop/271747/1 "2008-09-27T17:40:21Z")

</div>

```auto
Hi I'm a relatively inexperienced actionscripter and wondered if anyone can help me understand why the code pastd below isn't working?
I'm trying to create a drag and drop activity and the idea is that my any of my draggable movieclips can be dropped on any of the drop movie clips. The problem is I can get any number of the draggable clicks to drop on one specific drop area. But when I insert a nested for loop which I had hoped would allow my drags to drop to any of the available drops it doesn't work. Here's a snippet of my code, I'll attach the whole thing at the bottom. Any help most welcome!

```

```auto
//STOP DRAG
for (var i = 0; i<numDrags; i++) {
 this["drag"+i].onRelease = this["drag"+i].onReleaseOutside=function () {
  this.stopDrag();
  checkPosition();
 };
}
//CHECK POSITION
function checkPosition() {
 for (var i = 0; i<numDrags; i++) {
  for (var j = 0; j<numDrags; j++) {
   if (this["drag"+i].hitTest(this["drop"+j])) {
    this["drag"+i]._x = this["drop"+j]._x;
    this["drag"+i]._y = this["drop"+j]._y;
   } else {
    this["drag"+i]._x = this["drag"+i].origX;
    this["drag"+i]._y = this["drag"+i].origY;
   }
  }
 }
}

```
