
Hi.....
How do you add event listeners in mxml components and AS3 components?
Can you give me the example for that so i can clearly understand....
Thanks

Ans:
addEventListner in MXML component:
<?xml version="1.0" encoding = 'utf-8'?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.controls.Alert;
public function Handler():void{
b1.addEventListener(MouseEvent.CLICK, alertbox, false, 0);
}
public function Handler1():void{
t1.text = 'click event disabled ';
b2.addEventListener(MouseEvent.CLICK, alertbox, true, 0);
}
public function alertbox(event:Event):void{
Alert.show('click event occured');
}
</mx:Script>
<mx:Button id = 'b1' label = 'b1 control' click = 'Handler()'/>
<mx:HBox>
<mx:Button id = 'b2' label = 'b2 control' click = 'Handler1()'/>
<mx:TextInput id = 't1' editable = 'false'/>
</mx:HBox>
<mx:Script>
public function message(event:Event):void{
Alert.show('welcome to Flex World');
}
</mx:Script>
<mx:HBox>
<mx:Label text = 'TextInput t2'/>
<mx:TextInput id = 't2'
click = 't2.addEventListener(MouseEvent.CLICK, message, true, 0);'
editable = 'true'/>
</mx:HBox>
<mx:HBox>
<mx:Label text = 'TextInput t3'/>
<mx:TextInput id = 't3'
click = 't3.addEventListener(MouseEvent.CLICK, message, false, 0);'
editable = 'false'/>
</mx:HBox>
</mx:Application>
addEventListner in Action Script component:
package myComponents
{
import mx.controls.TextArea;
import flash.events.Event;
public class ModalText extends TextArea {
public function ModalText() {
super();
addEventListener("enableChanged", enableChangedListener);
}
public function enableInput(value:Boolean):void {
dispatchEvent(new Event("enableChanged"));
}
private function enableChangedListener(eventObj:Event):void {
// Handle event.
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.