# Event Listeners and Movie Clips stored in array

**URL:** <https://forum.kirupa.com/t/event-listeners-and-movie-clips-stored-in-array/258037>\
**Category:** flash\
**Created:** [April 20, 2008, 2:18am UTC](https://forum.kirupa.com/t/event-listeners-and-movie-clips-stored-in-array/258037 "2008-04-20T02:18:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![webmaster4u](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/webmaster4u/32/3478_2.png) [@webmaster4u](https://forum.kirupa.com/u/webmaster4u)\
**Post date:** [April 20, 2008, 2:18am UTC](https://forum.kirupa.com/t/event-listeners-and-movie-clips-stored-in-array/258037/1 "2008-04-20T02:18:39Z")

</div>

I have about 20 clips generated randomly, and they are stored in an array.

I create a for statement that cycles through the clips and adds random properties.

To add event listeners to each clip that I cycle through, how do I get around this:

```auto

  var clipData:Array=new Array;

  clipData['clip01'] = ({lbl: 'clip01', url: 'swf/clip01.swf'});
  clipData['clip02] = ({lbl: 'clip02', url: 'swf/clip02.swf'});

  for (var clipIndex:String in clipArr) {
    ... code for adding properties here ...

    ... event listener part ...
    if (clipIndex == 'clip01'){clipData[clipIndex].addEventListener(MouseEvent.MOUSE_OVER, overHandler1);}
    if (clipIndex == 'clip02'){clipData[clipIndex].addEventListener(MouseEvent.MOUSE_OVER, overHandler2);}

  }

  function overHandler1(e:Event):void{ overHandler(1); }
  function overHandler2(e:Event):void{ overHandler(2); }

  function overHandler(clipIndex:String):void{
    trace(clipData[clipIndex]['lbl']);
  }

```

Thew above works, but when I have 20 event handler functions for the same thing, it get s reduntant.

Plus the amount of clips may change dynamically depending on user input… any way around this?
