# Looping through 2 arrays and repositioning movieclips

**URL:** <https://forum.kirupa.com/t/looping-through-2-arrays-and-repositioning-movieclips/246724>\
**Category:** flash\
**Created:** [December 13, 2007, 8:05pm UTC](https://forum.kirupa.com/t/looping-through-2-arrays-and-repositioning-movieclips/246724 "2007-12-13T20:05:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pixel\_chick](https://avatars.discourse-cdn.com/v4/letter/p/eada6e/32.png) [@pixel\_chick](https://forum.kirupa.com/u/pixel_chick)\
**Post date:** [December 13, 2007, 8:05pm UTC](https://forum.kirupa.com/t/looping-through-2-arrays-and-repositioning-movieclips/246724/1 "2007-12-13T20:05:55Z")

</div>

I have a mad-lib type page that I am trying to put together. There are 27 words that have all been converted to movie clips named word1, word2, etc., that make up my first array. There are 3 layers inside each movie clip: a ‘hit’ layer, a text layer, and a bg layer. The on mousedown event grabs the hit layer. The second array has 6 items in it called blank1, blank2, etc. I am doing a hitTest so that if one of the words is over the blank it will snap to the blank movie clip x, y position. I am having major difficulty getting the movie clip to snap back to its original position if the hitTest is false. Here is my code:

```auto
stop();
var main:DisplayObject = this;
buttonMode = true;

function init():void{
    for(var i:uint = 1;i<28;i++){
        main["word"+i]['hit'].addEventListener(MouseEvent.MOUSE_DOWN,wordClick);
        main["word"+i]['hit'].addEventListener(MouseEvent.MOUSE_UP, wordRelease);
        main["word"+i].oX = main["word"+i].x;
        main["word"+i].oY = main["word"+i].y;        
    }//end for    
}//end init

function wordClick(e:MouseEvent){
    e.target.parent.startDrag();    
}//end word Click

function wordRelease(e:MouseEvent):void {
    for (var n:uint = 1; n<7; n++) {
        if (e.target.parent.hitTestObject(main['blank'+n])) {
            e.target.parent.stopDrag();
            e.target.parent.x = main['blank'+n].x;
            e.target.parent.y = main['blank'+n].y;
            e.target.parent['bg'].alpha = 0;
        } else {
            e.target.parent.stopDrag();
        }
    }//end for loop
} //end wordRelease

init();

```

Also, there is a reset button that is supposed to send the words back to their original position but I’m not sure how to do that outside of the for loop.

Thanks!
