2 Replies Latest reply on Oct 18, 2006 5:23 PM by Josh Johnson

    Connecting a Tree to a ViewStack

    Josh Johnson Level 1
      So I have a tree, where each node in the tree represents a view, and these views can be arranged hierarchically.

      - view 1
      - view 2
      - view 3
      - view 4

      I also have a viewstack that includes corresponding display items for each view.

      <viewstack id="viewContentStack">
      <panel id="v1" />
      <panel id="v2" />
      <panel id="v3" />
      <panel id="v4" />

      To connect the two, I created an XML List Collection that defined the tree items, and also contained references to the panels in the viewContentStack like so...

      <mx:XMLListCollection id="viewTreeData">
      <mx:XMLList xmlns="">
      <viewName label="View 1" viewStack="v1">
      <viewName label="View 2" viewStack="v2" />
      <viewName label="View 3" viewStack="v3" />
      <viewName label="View 4" viewStack="v4" />

      My problem is this. I tried to link the two together using the change event on the tree like so:

      change="viewContentStack.selectedChild=this[viewTreeData.getItemAt(viewTree.selectedIndex ).@viewStack]"/>

      But the problem is that this only takes into consideration the Index of the selected tree item, which changes based on whether the tree is expanded or not. (If the tree is collapsed, View 4 is index 2, but if the tree is open, it's index 4.) Is there a better way to extract the viewStack data from the XML for only the selected view, where it won't change based on the state of the tree?