Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Flex Flex Remove Event Listener example

Related Tutorials


 
 

Share on Google+Share on Google+

Flex Remove Event Listener example

Advertisement
Following example shows the work of removeEventListener method which is an in-built function.

Flex removeEventListener example

     

In the example below flex removeEventListener method working is demonstrated. This method removes the events from the flex components. Here mouse click event are removed by the method. In the example method doesn't able to remove the event from the button with id b3 because on this flex control, the associated event is built with the button click attribute.
And this button control tag is under mxml tags, this shows that events cannot be removed that are added inside the mxml tags.
 

 

 

 

 

 

removelistener.mxml

<?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 = 
   'al
ertbox(event);'/>
  
  </mx:HBox>

  <mx:TextInput text = 'click to remove click action
  click = 'removeEvent()' editable = 'false'/>

</mx:Application>

removelistener.swf

 

 

Download the code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 9, 2008

Related Tutorials

Discuss: Flex Remove Event Listener example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com