1 Reply Latest reply on Oct 11, 2010 6:18 AM by Lior Bruder

    Accessing containers in sibling MXML components

    Chris Callaghan

      New to Flex, but trying to separate my app into managable MXML components, but I'm struggling with accessing

      components in different MXML files.

       

      Simplified view below...

       

       

      project

      • (default package)
        • Main.mxml
      • components
        • AppAccordion
        • Component 1
        • Component 2
        • Component 3

       

       

      Main.mxml has the custom component called "AppAccordion" in it with the id="myAccordion".

       

      AppAccordion has 3x canvases which implement each of the custom Components 1, 2 or 3 mxml files. So each "Component N" mxml file appears as a different item of the accordion.

       

      My problem is that I want a button in "Component 1" to change the selectedIndex of "myAccordion", but I have no idea how to do this. I can trace (parent.parent.parent) and this gives me the name of the accordion, but when I try (parent.parent.parent.selectedIndex) it says its an undefined property?!?!

       

      Any help would be much appreciated

       

      Thank you!

        • 1. Re: Accessing containers in sibling MXML components
          Lior Bruder

          The right way (As for architecture point of view) will be to send event from the

          component:

           

          var myEvent:MyEvent = new MyEvent(newIndex);

          dispatch(myEvent);

           

          And catch it on the main application:

           

          in the main app: _component1.addEventListener(MyEvent.EVENT_NAME, MyFunction).

           

          And in the main app add the callback:

           

          private function MyFunction(param:int):void {

             // here u get the new index and change the accordion


          }

           

          * for creating custom events you can check "Flex in a week", day 3

           

          Lior