3 Replies Latest reply on Aug 13, 2008 6:06 AM by Newsgroup_User

    Loose Coupled Events

    Ludo99
      Is it possible for an event to be "broadcast" to all the components in an application so any component that wants to use the event can access it?
      I have an application which contains a number of components contained within components. On one side is a datagrid and when an item is selected I would like the details of that record to appear in the child of a panel component.
      The dispatching of the event is OK and the event is captured in the Application (where the datagrid is contained as a component) but in order to get the event to child component, I have to include a handler in the Application that sends the event to the child which then has a second handler to move it on to the child.
      Is there any way that a component can just "listen" out for an event without it being handed down the chain? In other words, can the Application broadcast the event to all the components (children, grandchildren etc) and then any child that wants that event would simply listen out for it?
      Sorry about the rambling question. If anyone has an answer to this, I think it would be really useful in a component based application.
      Thanks
        • 1. Re: Loose Coupled Events
          Level 7

          "Ludo99" <webforumsuser@macromedia.com> wrote in message
          news:g7retf$i0o$1@forums.macromedia.com...
          > Is it possible for an event to be "broadcast" to all the components in an
          > application so any component that wants to use the event can access it?
          > I have an application which contains a number of components contained
          > within
          > components. On one side is a datagrid and when an item is selected I would
          > like
          > the details of that record to appear in the child of a panel component.
          > The dispatching of the event is OK and the event is captured in the
          > Application (where the datagrid is contained as a component) but in order
          > to
          > get the event to child component, I have to include a handler in the
          > Application that sends the event to the child which then has a second
          > handler
          > to move it on to the child.
          > Is there any way that a component can just "listen" out for an event
          > without
          > it being handed down the chain? In other words, can the Application
          > broadcast
          > the event to all the components (children, grandchildren etc) and then any
          > child that wants that event would simply listen out for it?
          > Sorry about the rambling question. If anyone has an answer to this, I
          > think it
          > would be really useful in a component based application.

          Look at binding. Check out how they use loosely coupled binding here
          http://www.returnundefined.com/2006/11/creating-truly-reusable-renderers-with-classfactory


          • 2. Re: Loose Coupled Events
            Ludo99 Level 1
            Thanks for the reply Amy.
            I am a bit new to all this so I might be missing something but I dont think that is quite what I was looking for.
            The application I have looks like this:
            ==========
            Application
            - Panel
            - - DataGrid
            - Canvas
            - - Panel
            - - - VBox
            - - - - Label
            - - - VBox
            - - - - Label
            ==========
            I would like the dataGrid to dispatch an ItemClicked event and for both the labels to be able to pick up a value in that event without having to define the event in anything that contains that Label.
            In other words, I would like to include a line of code in each Label that references the datagrid event, but not to include reference to it anywhere else.
            Is this possible? Without it, I dont think it looks like loose coupling to me.
            Thanks again,
            Ludo
            • 3. Re: Loose Coupled Events
              Level 7

              "Ludo99" <webforumsuser@macromedia.com> wrote in message
              news:g7ul5i$8f8$1@forums.macromedia.com...
              > Thanks for the reply Amy.
              > I am a bit new to all this so I might be missing something but I dont
              > think
              > that is quite what I was looking for.
              > The application I have looks like this:
              > ==========
              > Application
              > - Panel
              > - - DataGrid
              > - Canvas
              > - - Panel
              > - - - VBox
              > - - - - Label
              > - - - VBox
              > - - - - Label
              > ==========
              > I would like the dataGrid to dispatch an ItemClicked event and for both
              > the
              > labels to be able to pick up a value in that event without having to
              > define the
              > event in anything that contains that Label.
              > In other words, I would like to include a line of code in each Label that
              > references the datagrid event, but not to include reference to it anywhere
              > else.
              > Is this possible? Without it, I dont think it looks like loose coupling to
              > me.
              > Thanks again,

              You don't need to worry about loose coupling when all objects have the same
              scope. Probably the easiest way to handle this is simply to bind those
              labels to properties of yourDatagrid.selectedItem.

              HTH;

              Amy