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:
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?