# Trying to add listeners to array of MCs

**URL:** <https://forum.kirupa.com/t/trying-to-add-listeners-to-array-of-mcs/271292>\
**Category:** flash\
**Created:** [September 20, 2008, 11:40pm UTC](https://forum.kirupa.com/t/trying-to-add-listeners-to-array-of-mcs/271292 "2008-09-20T23:40:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Loki\_develop](https://avatars.discourse-cdn.com/v4/letter/l/71e660/32.png) [@Loki\_develop](https://forum.kirupa.com/u/Loki_develop)\
**Post date:** [September 20, 2008, 11:40pm UTC](https://forum.kirupa.com/t/trying-to-add-listeners-to-array-of-mcs/271292/1 "2008-09-20T23:40:45Z")

</div>

So i’m trying to add event listeners to an array of movie clips. the array values will match the instance names of the MCs. but I’m having a hard time getting the function to work in the first place. mainly because this is my first AS3 project.

heres what I’ve got so far:

```auto
 
stop();
import flash.external.*;
function mapTree():void {
 var buttons:Array = new Array();
 buttons[0] = "kether";
 
 for (var i:int = 0; i < buttons.length; i++) {
  var elem:MovieClip = buttons*;
  var branch:String = buttons*;
  elem.addEventListener(MouseEvent.CLICK, createListener(branch));
 }
}
function createListener(branch:String):Function {
 var foo:Function = function (evt:MouseEvent):void {
  var jsFunc:String = "sprout";
  var id:String = String(branch) + "_branch";
  var className:String = "";
  ExternalInterface.call(jsFunc, id, className);
 }
 return foo;
}
mapTree();

```

obviously the array will become much longer. but I could really use some help. the listener is basically just supposed to fire off a js function, and I actually got that part to work. (i was targeting a single mc) and now that I’ve thrown an array in to try and make the addition of listeners simpler I can’t get it right. what am I doing wrong?
