Mega Code Archive

 
Categories / Flex / Event
 

Use addEventListener function to bind function to event

<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init(event)">     <mx:Script>                       import flash.events.MouseEvent;                         private function init(e:Event):void          {             myButton.addEventListener(MouseEvent.CLICK,clickBtn_1);                       myPanel.addEventListener(MouseEvent.CLICK,clickPanel);                     }                  private function clickBtn_1(evt:MouseEvent):void         {             myText.text += "Button 1 clicked !";                             evt.stopImmediatePropagation();                  }                  private function clickPanel(evt:MouseEvent):void         {              myText.text += "Panel clicked";         }        </mx:Script>     <mx:Panel id="myPanel" title="Stop Prapagation">              <mx:Button id="myButton" label="Enter name"/>         <mx:TextArea id="myText" width="275" height="171"/>          </mx:Panel>      </mx:Application>