2 Replies Latest reply on Mar 17, 2010 1:36 PM by msakrejda

    Event propagation API




      I recently started using Flex and read through the, very extensive and well written documentation. I read about the event propagation mechanism and was rather stunned that only Objects that have a parent-child relationship take part in event propagation. At first I couldn't believe it but trying to connect to objects that were at very different parts of the display list showed, that the events really do not get delivered! Wouldn't it be better to have a more general mechanism that does not care about the wherabouts of the components? I mean, what if I want to synchronize some model objects that are not even part of the display list with some UI Element they have a relationship with? The target phase doesn't work because its not the model that throws the event (of course!). Or do I miss something here?


      I was expecting a more subject-observer like pattern,  that allows me to connect whatever I want with whatever there is left. So, how do I do that. Do I have to right my own little event dispatching library (what would not be so difficult, but I would rather use something that has already proven its liability)? Can anybody recommend me a good API for that or tell me that I am dead wrong and missing something important?




        • 1. Re: Event propagation API
          Flex harUI Adobe Employee

          Only DisplayObjects support bubble and capture propagation.  In a tree of

          regular Objects, as long as you attach a listener to the right object, you

          will be able to get its events.


          Bubble and capture are very dangerous as they break encapsulation.  We only

          use them for situations where the target is unpredictable like in mouse and

          keyboard interaction.  I would probably not use it in a data object tree.


          Maybe if you provide a more explicit example of what you are trying to

          accomplish and what you tried, folks on the forum can help.

          • 2. Re: Event propagation API
            msakrejda Level 4

            I think you're missing the distinction (admittedly, not very clearly made in a lot of documentation) between display list event propagation and the standard Observer pattern in Flex. You can still use the standard Observer pattern with IEventDispatcher. You just need to listen directly to the object that will be dispatching the events. In fact, for non-display-list objects (e.g., your application's data model), you have to do this.