2 Replies Latest reply on May 15, 2008 1:22 PM by seguetester2

    Children Hearing Parent (or Sibling) Events

      I have an application that has a dozen or so of the same custom components on a canvas. If I click on one of the objects I want the other 11 to all react to that event. Given that I am rather new to Flex, I am a bit puzzled. Trace statements show that all 12 components are all listening for the event; however, it appears that when I click on one of the components the other 11 are not in the bubbling path. So, I guess my question is how can multiple children hear an event from their parent...or a sibling?

      Thanks in advance...
        • 1. Re: Children Hearing Parent (or Sibling) Events
          ntsiii Level 3
          One easy way to do this is to have each child dispatch a named event. make it bubbling, if the children are nested below the main app.

          Have a single listener for that named event in the main app. Have the handler dispatch another event(or a clone of the one it receives). Have each child listen to the main app for that event.
          In each child component:
          private var _app:Application;
          in an init function:
          _app = mx.core.Application.application;
          _app.addEventListener("myNamedEvent", myNamedEventHandler);


          • 2. Re: Children Hearing Parent (or Sibling) Events
            seguetester2 Level 1
            Hey Tracy,

            Thanks for the advice. I was struggling with adding the listener to the stage; however, the stage does not appear to be available until after the application creation is complete. While your solution did not work for me exactly as you presented it, it was the key that I needed. All that I had to do was add the the following to the init for my component:

            Application.application.addEventListener("clearOthers", onClearOthers);

            No need to declare a variable since Application.application is static. Works like a charm!!!

            Thanks again for your help,