<?xml version = '1.0' encoding = 'utf-8'?>
<mx:Application xmlns:mx = 'http://www.adobe.com/2006/mxml'
initialize = 'addEvent();'>
<mx:Script>
import mx.controls.Alert;
public function addEvent():void{
b1.addEventListener(MouseEvent.CLICK, alertbox, false, 0);
}
public function removeEvent():void{
b1.removeEventListener(MouseEvent.CLICK, alertbox);
b2.removeEventListener(MouseEvent.CLICK, alertbox);
b3.removeEventListener(MouseEvent.CLICK, alertbox);
}
public function alertbox(event:Event):void{
Alert.show('Mouse click event occured');
}
</mx:Script>
<mx:HBox>
<mx:Button id = 'b1' label = 'b1 button'/>
<mx:Button id = 'b2' label = 'b2 button'
initialize = 'b2.addEventListener(MouseEvent.CLICK, alertbox, false,0);'/>
<mx:Button id = 'b3' label = 'b3 button' click = 'alertbox(event);'/>
</mx:HBox>
<mx:TextInput text = 'click to remove click action'
click = 'removeEvent()' editable = 'false'/>
</mx:Application>
|