5 Replies Latest reply on Mar 13, 2009 7:02 AM by Newsgroup_User

    Targeting Parent Components in Flex

    released87
      Hi,

      I am pretty new to Flex (< 2 weeks), and I have started building a new site. I have basically created a Hiearchy of mxml components and actionscript classes. I am using the following classes for this issue:

      AS Class: store.classes.Products
      Parent (Flex MXML Component): store.visual.main.main_products
      Component View 1 (Flex MXML Component): store.visual.main.products.products_list
      Component View 2 (Flex MXML Component): store.visual.main.products.products_details


      I am trying to figure out how I can target the parent component, particularly the ViewStack, to create a method in my Products class that can be used to switch the two child views; the list view and the details view.

      I am really looking for an explanation of how I can communicate between child/parent Flex components with the same Data and Classes. In Flash I could use something like _root.main.products_main.ViewStack.selectedChild= productObject.product_Level; to change the stack.

      Help would be greatly appreciated...
        • 1. Re: Targeting Parent Components in Flex
          Mainmanian Level 1
          I have used a means of communication between teh parent component and the child class that has worked for me quite well.

          I call the child class passing in the parent component's controls or components. For instance, from the init() (called by creationComplete())of the parent component, i send in the parent component's canvas or another component that is defined in the parent.

          HTH, Ramesh
          • 2. Re: Targeting Parent Components in Flex
            Garyl Woolworth Level 1
            Well to start you off with the lingo change from Flash to Flex you can think of what used to be _root as Application.

            So if you wanted to scope all the way from the top you would do something like what I've attached. I don't really recommend always trying to scope things from the Application though. It adds a lot of unneeded code if your structure is thought out well enough. If you wanted to go from store.visual.main.products.products_list to store.visual.main.products you can do this.parentDocument.selectedChild = this.parentDocument.whatever;

            Hope this helps get you started in the right direction.
            • 3. Re: Targeting Parent Components in Flex
              Level 7

              "released87" <webforumsuser@macromedia.com> wrote in message
              news:gpboqv$inp$1@forums.macromedia.com...
              > Hi,
              >
              > I am pretty new to Flex (< 2 weeks), and I have started building a new
              > site. I
              > have basically created a Hiearchy of mxml components and actionscript
              > classes.
              > I am using the following classes for this issue:
              >
              > AS Class: store.classes.Products
              > Parent (Flex MXML Component): store.visual.main.main_products
              > Component View 1 (Flex MXML Component):
              > store.visual.main.products.products_list
              > Component View 2 (Flex MXML Component):
              > store.visual.main.products.products_details
              >
              >
              > I am trying to figure out how I can target the parent component,
              > particularly
              > the ViewStack, to create a method in my Products class that can be used to
              > switch the two child views; the list view and the details view.
              >
              > I am really looking for an explanation of how I can communicate between
              > child/parent Flex components with the same Data and Classes. In Flash I
              > could
              > use something like _root.main.products_main.ViewStack.selectedChild=
              > productObject.product_Level; to change the stack.

              http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf Q3


              • 4. Re: Targeting Parent Components in Flex
                released87 Level 1
                thank you all for your responses, one more question...

                i have a Products class that I will be using to load XML from a Database using PHP. The PHP outputs well-formed XML to be loaded into the class. From there I put it into a Collection to be displayed within the Products page. However, I have 3 different components within the Products page; a list/thumbnail page, a details page, and a filter that uses a tree component to sort by category/subcategory. How do instantiate the Products class so the parent and all 3 children use the same object, so I can filter the list view using the filter component, and view details using the details component. If I create one Products object in the parent will the 3 children be able to call methods from that same Object? When the .SWF compiles, I would imagine it would all be the same Object, is that correct?

                Thanks so much...
                • 5. Re: Targeting Parent Components in Flex
                  Level 7

                  "released87" <webforumsuser@macromedia.com> wrote in message
                  news:gpdmml$1hd$1@forums.macromedia.com...
                  > thank you all for your responses, one more question...
                  >
                  > i have a Products class that I will be using to load XML from a Database
                  > using
                  > PHP. The PHP outputs well-formed XML to be loaded into the class. From
                  > there I
                  > put it into a Collection to be displayed within the Products page.
                  > However, I
                  > have 3 different components within the Products page; a list/thumbnail
                  > page, a
                  > details page, and a filter that uses a tree component to sort by
                  > category/subcategory. How do instantiate the Products class so the parent
                  > and
                  > all 3 children use the same object, so I can filter the list view using
                  > the
                  > filter component, and view details using the details component. If I
                  > create one
                  > Products object in the parent will the 3 children be able to call methods
                  > from
                  > that same Object? When the .SWF compiles, I would imagine it would all be
                  > the
                  > same Object, is that correct?

                  I'd highly suggest that you get Flex 3 Training from the Source, because it
                  goes through building an application much like yours in great detail.