2 Replies Latest reply on May 17, 2008 2:10 PM by mchtower

    Accessing Items Across Components

    mchtower Level 1
      Hello All,

      I'm having trouble figuring out how to access items (in this case an accordion) across components.

      In my application I have a main.mxml file which contains a viewstack that uses homeview.mxml and buyersview.mxml to display different content.

      buyersview.mxml contains an accordion that I'd like to be able to access from homeview.mxml. I tried using click="this.parentApplication.buyersview.buyersAccordion.selectedIndex=1". This does not return an error but it doesn't work either.

      Any help would be appreciated
        • 1. Re: Accessing Items Across Components
          ntsiii Level 3
          You are or will be hitting the deferred instantiation issue. Non-visible children of ViewStack or Accordion, are not created until the user navigates to that view.

          It is bad practice to attempt to set component properties from the outside, and this is one reason. Instead, use the creationComplete and/or show events to "pull" the data you want into the component.

          Your theory is good on the inter-component communication. You may need to approach it one step at a time to verify your expression. Application.application resolves to the top-level application scope. I tend to use that more than parentDocument.

          Tracy
          • 2. Re: Accessing Items Across Components
            mchtower Level 1
            Tracy,

            Thanks for your reply.

            I'm not entirely clear what you meant by this:

            It is bad practice to attempt to set component properties from the outside, and this is one reason. Instead, use the creationComplete and/or show events to "pull" the data you want into the component.

            The accordion I'm trying to access is not in the application mxml file it is in a custom component file. Are you saying this is bad design and I should rearrange the application structure?

            Thanks,

            Michael