I have 20 buttons on my stage, and rather then have ‘removeEventListener’ for each button, i wanted to use a loop to do so. Heres what i have done.
//array containing the buttons instance names.
var soundArray:Array = new Array();
var buttonsOnArray:Array = new Array();
//event listener for the button i wish to turn off once its selected.
mainHold.Bass1_mc.addEventListener(MouseEvent.CLICK, soundSelected);
//this function is called once the button is clicked, so i want it to disable whatever button was clicked
function soundSelected(evt:MouseEvent):void{
soundArray.push(evt.target.fileName);//pushes the filename into a playlist array.
buttonsOnArray.push(evt.target.name);//pushes the instance names of the buttons 'on'.
trace ("PlayList = "+soundArray);
trace ("Buttons On are ="+buttonsOnArray);
//trace (evt.target.name);
for (var i:int = 0; i < buttonsOnArray.length; i++)
{
buttonsOnArray*.removeEventListener(MouseEvent.CLICK, soundSelected);
}
}
However this doesnt seem to work, it still keeps the button as active, basically each button adds a filename (that i have assigned to it) to a playlist array (soundArray), but i only want it to add it once.
Please help im going mad.
Thanks.