AmyCohen
09-21-2009, 08:13 PM
Hello! This is my first post in a programming forum, so I apologize in advance for any (unintentionally!) bad forum etiquette.
I've written a loop using ActionScript that automatically creates checkboxes. The checkboxes are created and displayed just fine. The problems begin when I try to add an event listener to each individual checkbox that's established within the loop. For some reason, the only target that is received by the function that is called by the event listener is the last checkbox established in the loop. Here is a snippet from my code:
for (var m:Number = 0; m < numLayers; m++){
var check:CheckBox = new CheckBox();
check = checkArray[m];
legend.addChild(check);
check.name = "check" + ((m + 1).toString());
trace(check);
check.addEventListener(Event.CHANGE, function (e:Event):void{
trace(check);
addPolyLayer(check);
});
}
Any advice would be greatly appreciated!
-Amy-
I've written a loop using ActionScript that automatically creates checkboxes. The checkboxes are created and displayed just fine. The problems begin when I try to add an event listener to each individual checkbox that's established within the loop. For some reason, the only target that is received by the function that is called by the event listener is the last checkbox established in the loop. Here is a snippet from my code:
for (var m:Number = 0; m < numLayers; m++){
var check:CheckBox = new CheckBox();
check = checkArray[m];
legend.addChild(check);
check.name = "check" + ((m + 1).toString());
trace(check);
check.addEventListener(Event.CHANGE, function (e:Event):void{
trace(check);
addPolyLayer(check);
});
}
Any advice would be greatly appreciated!
-Amy-