4 Replies Latest reply on Apr 1, 2010 1:53 AM by Nedumangad

    How to catch an event with a handler ?

    Nedumangad Level 1

      Hi,

        I am beginner in flex.To my best of knowledge,addEventListener() is always associated with a component.(say button1.addEventListener(MouseEvent.CLICK,myHandler)).

        But suppose,I need to catch a particular type of event(say 'click') using a function without specifying any particular component as the event source.Means,say I have 4 components in my application and I have one handler function for catching one particular type of event(that may be a cutom event).But I dont add any listener for any components.

      In a nutshell,my question is,how can I catch one particular type of event whenever this type of event is dispatched or triggered in my application ? or I need a function which will be invoked whenever a particular type of event is triggered in my application...

        • 1. Re: How to catch an event with a handler ?
          msakrejda Level 4

          Read up on the DOM event model and event bubbling. This essentially lets you listen for (some) events on the Application object itself. Any bubbling events dispatched by children of the Application (or their children, and so on) eventually bubble up to Application itself, and you can listen for them there.

          • 2. Re: How to catch an event with a handler ?
            Nedumangad Level 1

            Thanks for the info.But I need to create a component which will do something when a partiuclar type of event is triggered in an application.For eg,I will create a custom HBox  so that whenever a particular type of event is triggered in the application,its colour will be changed.But in the application,I should not use this component identifier.(Application doesnot know about this compoent)

            • 3. Re: How to catch an event with a handler ?
              Gregory Lafrance Level 6

              Try adding the event listener to the systemManager:

               

              systemManager.addEventListener(MouseEvent.CLICK, myClickListener);

               

              Then check the currentTarget/target.

               

              If this post answers your question or helps, please mark it as such.


              Greg Lafrance - Flex 2 and 3 ACE certified

              www.ChikaraDev.com

              • 4. Re: How to catch an event with a handler ?
                Nedumangad Level 1

                Can u explain this,pls..? U mean,I should use systemManager.addEventListener(MouseEvent.CLICK, test); in the constructor of my custom component ? Then if I add this component in my application and not using any event listener for this in that application,the method "test()" will be invoked when CLICK event is triggered from any of the compoents in the application ? Please expain...