2 Replies Latest reply on May 16, 2006 8:15 PM by GordonSmith

    Accessing ViewStack with AS from custom compoenent

    uprise78
      Hello,

      I cant seem to be able to figure out how to access a viewstack to change the selected index from within a customer componenet. The structure that I am working with is something like this:

      <mx:ViewStack id="mainViewStack" borderStyle="solid">
      <mx:Panel id="displayAll" label="Display All Customers" width="100%" height="100%" headerHeight="6">
      <ns1:DisplayAllGrid verticalCenter="0" horizontalCenter="0"/>
      </mx:Panel>
      <mx:Panel id="search" label="Search" width="100%" height="100%">
      <mx:Label text="Search" />
      </mx:Panel>
      <mx:Panel id="customerView" label="Customer Information" width="100%" height="100%">
      <mx:Label text="Customer View" />
      </mx:Panel>
      </mx:ViewStack>

      There is a link in the ":DisplayAllGrid" that I would like to use to change the mainViewStacks selected panel. Does anyone know how to accomplish this?

      Thanks in advance,
      Mike
        • 1. Re: Accessing ViewStack with AS from custom compoenent
          Level 7
          You have two choices. You can pass in the mainViewStack as a property to
          your DisplayAllGrid. In your grid class, you'd then save this value and then
          modify selectedIndex when you press your link.

          The other option is to use parent.parent.selectedIndex (or perhaps further
          up the parent chain depending on the scope of the call). Using this is a bit
          more hacky and breaks encapsulation. I'd advise using the first technique.

          --
          Jason Szeto
          Adobe Flex SDK Developer


          "uprise78" <webforumsuser@macromedia.com> wrote in message
          news:e3kqlr$sic$1@forums.macromedia.com...
          > Hello,
          >
          > I cant seem to be able to figure out how to access a viewstack to change
          > the
          > selected index from within a customer componenet. The structure that I am
          > working with is something like this:
          >
          > <mx:ViewStack id="mainViewStack" borderStyle="solid">
          > <mx:Panel id="displayAll" label="Display All Customers"
          > width="100%"
          > height="100%" headerHeight="6">
          > <ns1:DisplayAllGrid verticalCenter="0" horizontalCenter="0"/>
          > </mx:Panel>
          > <mx:Panel id="search" label="Search" width="100%" height="100%">
          > <mx:Label text="Search" />
          > </mx:Panel>
          > <mx:Panel id="customerView" label="Customer Information"
          > width="100%"
          > height="100%">
          > <mx:Label text="Customer View" />
          > </mx:Panel>
          > </mx:ViewStack>
          >
          > There is a link in the ":DisplayAllGrid" that I would like to use to
          > change
          > the mainViewStacks selected panel. Does anyone know how to accomplish
          > this?
          >
          > Thanks in advance,
          > Mike
          >


          • 2. Re: Accessing ViewStack with AS from custom compoenent
            GordonSmith Level 4
            If the code that you want to set the selectedIndex of the ViewStack is inside the DisplayAllGrid component, you should be able to use parentDocument.mainViewStack.selectedIndex; parentDocument lets you reference things on the document that contains your component. You don't have to -- and shouldn't -- walk parent by parent.

            Another approach is to have DisplayAllGrid dispatch some custom event when it want the mainViewStack to change its selectedIndex.Then in mainViewStack's initialize handler, do myDisplayAllGridComponent.addEventListener(...) to register a handler which sets the selected index.