2 Replies Latest reply on Nov 21, 2008 6:35 AM by Newsgroup_User

    Best way to communicate between custom components

    ironblunt
      Hi all,

      Just started using flex in the past couple of weeks and while I think I have the hang of the basic stuff, I wanted to move onto a more realistic project and ran into some confusion.

      Basically, I have an app that will load up an XML file and has a bunch of custom components. What I'd like to do is load up the XML file in the main application and have the results of the parsed XML available to all the custom components.

      So if I have a combo box in one of my custom components, I would like for it to get it's dataprovider from the reloaded XML file.

      So I looked through some books and several other online sites and I think there are 3 strategies but some are less elegant than others.

      1) My first inclination is to trigger an XMLFileLoaded event when the application loads or reloads the xml file and have that event dispatched and add handlers to all my custom components to deal with the reloaded xml in it's own way. I'm having some difficulties here in that the application initialize event seems to dispatch before my custom component's preinitialization gets called so my event handlers aren't being registered in time for the first load of the XML file.

      2) My second one is to maintain a view state. This is something that's a bit new to me so I'm not sure how to use it or if it was meant to maintain an internal state of the app or just the user interface level stuff.

      3) reset the desired data in all the components. and manually propogate the event down the component hierarchy.

      Anyone with more experience on how best to handle such a case, I'd really appreciate any advice.

      Thanks

      spark
        • 1. Re: Best way to communicate between custom components
          SujitG Level 2
          Hi,

          I would have created a VO (AS class) which is a singleton and create a variable which is Bindable and has the result of the parsed XML file. In my custom components i would have bound the components to the Bindable variable in the singleton VO created.

          This was marking your variable as Bindable will handle notifying all the bound components when the data changes. As the VO is singleton, you need not worry about multiple instances being created or making sure only one instance of the VO is used in all places.

          Hope this helps.
          • 2. Re: Best way to communicate between custom components
            Level 7

            "ironblunt" <webforumsuser@macromedia.com> wrote in message
            news:gg5g92$ftj$1@forums.macromedia.com...
            > Hi all,
            >
            > Just started using flex in the past couple of weeks and while I think I
            > have
            > the hang of the basic stuff, I wanted to move onto a more realistic
            > project and
            > ran into some confusion.

            Look at the answer to Q3 here:
            http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf

            It more focuses on communication up from the components to the application,
            but the links apply to your situation as well.

            Also, check out the terms "getter" and "setter" in the Help. Also look up
            the word "binding."

            HTH;

            Amy