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



Home Flex Flex adding single event on varied components Example

Related Tutorials


 
 

Share on Google+Share on Google+

Flex adding single event on varied components Example

Advertisement
Following example adds same MouseEvent.MOUSE_DOWN event listener on two check box controls

Flex single event on varied components

     

In the example below, listeners for a single event MouseEvent.MOUSE_DOWN, are created on two flex check boxes controls, due to which whenever the check boxes are clicked the  second argument of the .addEventListener method is get switched. 
Here the second argument of .addEventListener method is a function name eventHandler that contains show method of Alert class.
This show method when invoked opens the pop-up windows. So with this example a clear idea for adding single event listeners in to several components is depicted.

listener.mxml

<?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 eventHandler(event:Event):void{
  Alert.show('Id' + event.currentTarget.id 
  ' Class Name: ' + event.currentTarget.className 
  '\n' + event.currentTarget.label);
  
  }
  </mx:Script>
  
  <mx:CheckBox id = 'ch0' label = 'Check me permanently
  click = 'ch0.addEventListener(MouseEvent.MOUSE_DOWN, eventHandler);
 changeLabel0(event)'/>
  
  <mx:Script>
  public function addEvent():void{
  ch1.addEventListener(MouseEvent.MOUSE_DOWN, eventHandler);
  }
  </mx:Script>
  
  
  <mx:CheckBox id = 'ch1' label = 'Uncheck me permanently
  click = 'addEvent(); changeLabel1(event)' selected = 'true'/>
  
  <mx:Script>
  
  public function changeLabel0(event:Event):void{
  if(ch0.selected == 'false'){
  ch0.label = 'Check me permanently';
  }else {
  ch0.label = 'Well now i am checked permanently';  
  }
  }
  
  public function changeLabel1(event:Event):void{
  if(ch1.selected == 'true'){
  ch1.label = 'Uncheck me permanently';
  }else {
  ch1.label = 'Now i am Unchecked';
  }
  }
  
  </mx:Script>
  
</mx:Application>

 

listener.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 adding single event on varied components Example  

Post your Comment


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