My TEST button I want to expand and select on this XML Node
<view label="Info"  hidden="stations_info"/>

I've tried to modify this example to handle passing from a button but got no 
errors just doesn't work?

http://blog.flexexamples.com/2007/11/29/opening-nodes-in-a-flex-tree-control-using-the-expanditem-method/





<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute">
        
          <mx:Script>
        <![CDATA[

            [Bindable]
            public var selectedNode:XML;
            
            import mx.core.Container;
            
            // Event handler for the Tree control change event.
            public function treeChanged(event:Event):void {
                                
                selectedNode=Tree(event.target).selectedItem as XML;
                trace(selectedno...@hidden);
                //var treenode_form_class:treenode_form = new treenode_form( );
                //var viewstackformindex:Number = 
treenode_form_class.getViewStackFormIndex(selectedNode);
                                //mainviewstack.selectedIndex = 
selectedno...@hidden;
                                mainviewstack.selectedChild = 
Container(mainviewstack.getChildByName(selectedno...@hidden));
            }


            private function test(){

var node:XMLList =  treeData.root.main.view.(@hidden == 'stations_info');
                expandParents(node[0]);
                RootTree.selectedItem = node[0];
                var idx:int = RootTree.getItemIndex(node[0]);
                RootTree.scrollToIndex(idx);
                

                
            } 
            
            
            private function expandParents(node:XML):void {
                if (node && !RootTree.isItemOpen(node)) {
                    RootTree.expandItem(node, true);
                    expandParents(node.parent());
                }
            }
                        
                        
           // myViewStack.selectedChild = 
myViewStack.getChildByName(treeMenu.itemToLabel(treeMenu.selectedItem));
            
        ]]>
    </mx:Script>

           <mx:XMLList id="treeData">
        <root label="Root Tree">
            <main label="Announcements" hidden="announcements">
                <view label="Add"  hidden="announcements_add"/>
            </main>
            <main label="Stations" hidden="stations">
                <view label="Info"  hidden="stations_info"/>
            </main>
            
        </root>    
    </mx:XMLList>
        
    <mx:Panel title="Prototype" height="100%" width="100%" 
        paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10" >
                <mx:Button name="test" label="TEST" click="test()" />
        <mx:HDividedBox width="100%" height="100%">
            <mx:Tree id="RootTree" width="15%" height="100%" labelField="@label"
                showRoot="false" dataProvider="{TreeXMLList}" 
change="treeChanged(event)"/>
            <mx:ViewStack id="mainviewstack" width="85%">
              <mx:Canvas backgroundColor="#FFFFFF" id="announcements">
                <mx:Text text="Welcome to .... "
                    fontWeight="bold"
                    paddingTop="10" paddingLeft="10" />
              </mx:Canvas>
                          <mx:Canvas backgroundColor="#FFFFCC" 
id="announcements_add">
                <mx:Text text="This is Area 1"
                    fontWeight="bold"
                    paddingTop="10" paddingLeft="10" />
              </mx:Canvas>
              <mx:Canvas id="stations">
                <mx:Text text="STATIONS"/>
              </mx:Canvas>

            </mx:ViewStack>
        </mx:HDividedBox>
        
    </mx:Panel>

</mx:Application>


Reply via email to