Add handlers and then remove handlers
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="createHandler(event)">
<mx:Script>
import mx.controls.Alert;
private function createHandler(e:Event):void {
b1.addEventListener(MouseEvent.CLICK, myClickHandler);
}
private function removeMyHandlers(e:Event):void {
b1.removeEventListener(MouseEvent.CLICK,myClickHandler);
b2.removeEventListener(MouseEvent.CLICK,myClickHandler);
}
private function myClickHandler(e:Event):void {
Alert.show("This is a log message");
}
</mx:Script>
<mx:Button id="b1" label="Click Me" />
<mx:Button label="Click Me Too" id="b2"
click="myClickHandler(event)" />
<mx:Button label="Axe Listeners" id="b3"
click="removeMyHandlers(event)" />
</mx:Application>
Related examples in the same category