This works for a "click" event because it's a bubbling event that will "bubble up" the parent chain all the way to the Application. It wouldn't work for a "change" event, which is non-bubbling. However you can use the "capture phase" of event processing to give the Application a crack at an event. If you register an event handler with addEventListener() and pass true as the useCapture parameter, then the event processing will start at the Application (well, actually at the SystemManager) and go DOWN the parent chain to the target object.

 

- Gordon

 


From: [email protected] [mailto:[email protected]] On Behalf Of Sreenivas R
Sent: Thursday, March 16, 2006 7:51 AM
To: [email protected]
Subject: Re: [flexcoders] Need to add EventListener at the Application level

 

Here is a sample I wrote quicky. Hope it helps.

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="addHandler(event)"
xmlns="*">

<mx:Script>
 <![CDATA[
 
  public function addHandler(event:Event):void
  {
   this.addEventListener("click", changeHandler);
  }
  public function changeHandler(event:Event):void
  {
 // target points to the component which triggered the event  

 trace(event.type + " " + event.target);
  }
 ]]>
</mx:Script>

 <mx:TabNavigator>
  <mx:HBox label="Box1">
   <mx:Button id="bt1" label="Click Me 1" />
  </mx:HBox>
  <mx:HBox label="Box2">
   <mx:Button id="bt2" label="Click Me 2" />
  </mx:HBox>
  <mx:HBox label="Box3">
   <mx:Button id="bt3" label="Click Me 3" />
  </mx:HBox>
 </mx:TabNavigator>

</mx:Application>

 



 

On 3/16/06, KOT_MATPOC <[EMAIL PROTECTED]> wrote:

Hello,

is there a way to add an event listener to the Application so that it
would listen to ANY let's say "change" event that will be send from any
component within the application??
Is there also a way to tell dynamically WHICH component has sent this
event - for example TabNavigator, ViewStack etc... ?

Hope my question was clear.

Thanks a lot





--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links

<*> To visit your group on the web, go to:
   http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
   [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
   http://docs.yahoo.com/info/terms/






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to