3 Replies Latest reply on Aug 8, 2011 8:48 AM by Karl_Sigiscar_1971

    Passing Notifications to Interested Components

    l33tian Level 1

      Hey guys, i need some help in understanding custom events. I suppose flex is an event driven framework and i also noticed almost everything that happens is as a result of an event being fired directly or indirectly. so i came up with a solution to one of my problems and that was how to report certain events to other parts of my application by using the flex event system (dispatcher- listener model) to my advantage.


      For instance, i would like my main application( AIR) to listen for a custom event which would be dispatched by a titlewindow popup. this titlewindow popup is meant to contain a form which would make an insert operation in an SQLite database. The Main WindowedApplication contains a list that is modelled after the table that the titlewindow component updated! So i would like a situation where after titlewindow's Popupmanager.removed() is called, a custom event would be fired to notify any listener that a new data has been added to the database table. This would allow me to automatically refresh the contents of a list.


      My main question is:


      - Are Custom events listeners only tied to custom components?

      - is it possible to allow my main application window listen for costum events?


      I just feel the dispatcher-listener technique would be a very good way to pass messages and notifications around in my app! Any form of explaination would be greatly appreciated!

        • 1. Re: Passing Notifications to Interested Components
          Karl_Sigiscar_1971 Level 3

          Check Chapter 6 (Messaging) of the Parsley documentation:



          With this architectural framework, you will be able to dispatch a message (aka notification, aka event) from anywhere to anywhere in a fully decoupled way, which will solve a lot of your problems, especially when using a popup.

          With regular Flex events, you have the following problems:


          - If you dispatch a bubbling event, the target is the dispatching component and the component that is interested in the event needs to be in the display list and upper in the hierarchy. If it's a sibbling - at the same tree level in the hierarchy of the display list - or an object that is not in the display list - e.g because it's not currently added or non-visual -  it won't get the event.


          - If you dispatch a non-bubbling event, you dispatch it directly on the interested component. It becomes the target. The problem here is coupling. One class has to know about another.

          • 2. Re: Passing Notifications to Interested Components
            l33tian Level 1

            Thanks for the reply karl


            I checked it out and it looks good. Is there any way i can use the messaging API without working with MVC framework directly? I dont want to rewrite my application because i have come along way and i dont have much time! I just wished i started it out with this framework! It looks good.


            I guess i'm still stuck!

            • 3. Re: Passing Notifications to Interested Components
              Karl_Sigiscar_1971 Level 3

              No, you're not stuck.


              The good thing about Parsley is that you can take just the bits you need. It is not a MVC framework. It does not enforce MVC like some other frameworks though you can create a MVC type application with it.


              So, if you just want to use its Messaging features, you can.