Mega Code Archive

 
Categories / Flex / Components
 

Register a single listener function (myEventHandler()) to a Button and a CheckBox

<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"     creationComplete="initApp()">     <mx:Script>     public function initApp():void {         button1.addEventListener(MouseEvent.CLICK, myEventHandler);         cb1.addEventListener(MouseEvent.MOUSE_DOWN, myEventHandler);     }     public function myEventHandler(event:Event):void {         switch (event.currentTarget.className) {             case "Button":                 trace("Process Button click.");                 break;             case "CheckBox":                 trace("Process CheckBox click.");                 break;         }     }   </mx:Script>     <mx:Button label="Submit" id="button1" />     <mx:CheckBox label="All Words" id="cb1" />     <mx:TextArea id="ta1" text="Please enter a search term" width="200" /> </mx:Application>