# Loops and movieclip references

**URL:** <https://forum.kirupa.com/t/loops-and-movieclip-references/275362>\
**Category:** Uncategorized\
**Created:** [November 12, 2008, 10:26pm UTC](https://forum.kirupa.com/t/loops-and-movieclip-references/275362 "2008-11-12T22:26:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gstewart](https://avatars.discourse-cdn.com/v4/letter/g/87869e/32.png) [@gstewart](https://forum.kirupa.com/u/gstewart)\
**Post date:** [November 12, 2008, 10:26pm UTC](https://forum.kirupa.com/t/loops-and-movieclip-references/275362/1 "2008-11-12T22:26:50Z")

</div>

Hey,

I am sure I’ve done this before and it worked, not sure what I am not doing right.

I am creating 2 movieclips dynamically in a loop and attach a rollover event to one of them to manipulate the other one. Looks like this:

```auto

for(var i=0; i<5; i++){
    var clip1 = this.createEmptyMovieClip("cheese"+i, this.getNextHighestDepth());
    var clip2 = this.createEmptyMovieClip("burger"+i, this.getNextHighestDepth());
    
    clip2.onRollOver = function(){
        // do something with clip1, for example:
        clip1._visible = false;
    }
}

```

What happens is that when I roll over any of the clip2 movieclips they all modify the same clip1 movieclip, not the one that was created in the same loop cycle.

Any ideas?

G
