Why would you want to remove the click listener?
Just create weak references:
buttonContainer.addEventListener(MouseEvent.CLICK, action, false, 0, true);
buttonContainer.addEventListener(MouseEvent.MOUSE_OVER, action, false, 0, true);
buttonContainer.addEventListener(MouseEvent.MOUSE_OUT, action, false, 0, true);
var button:String = "";
function action(event:MouseEvent):void {
button = event.target.name;
switch (event.type) {
case MouseEvent.MOUSE_OVER :
//function here
break;
case MouseEvent.MOUSE_OUT :
//function here
break;
case MouseEvent.CLICK :
//function here
break;
}
}
If you wrap all of your button movieclips in “buttonContainer”, this all the code you will need for a virtually unlimited number of buttons.
You can use the button instance name as a test for downstream switch conditionals, since it has been stored within the “button” variable.
ie: if the variable button is equal to “btn1”, do something.
It will be equal to the instance name of whichever button you click.
That looks like an interesting technique but for now…
How do you remove the event listeners in this way. I know how to remove them when calling a function but I cannot get the syntax correct for this method.