6 Replies Latest reply on Dec 19, 2010 8:56 PM by saisri2k2

    How to expand a tree to node where label ="String"

    flexillu10 Level 1

      How can i get my tree to open the node at a given label? Example code would be brill.

       

      I'll mark correct answers as such

        • 1. Re: How to expand a tree to node where label ="String"
          flexillu10 Level 1

          Thought this would be simple?

          • 2. Re: How to expand a tree to node where label ="String"
            saisri2k2 Level 4

             

            I'll mark correct answers as such

            lol..!!

             

             

            lemme understnd the question, you want to expand a tree node programmatically?

             

            some code would help.. i'v seen something like

             

             

            in the API

            • 3. Re: How to expand a tree to node where label ="String"
              flexillu10 Level 1

              Yes i want to expand a given node in my tree.

               

              But the expanItem takes an object so i don't think i can use the label.

               

              here's my code, hope you can help..

               

              Tree

               

                   <mx:Tree id="menutree"  includeIn="browserState" showRoot="false" width="190" height="453" itemClick="menutree_itemClickHandler(event)" x="42.4" y="100.2"></mx:Tree>
              

               

               

              Here's how i populate my tree

               

                             protected function loadTreeData():void{
                             var treeLoader:URLLoader = new URLLoader(new URLRequest('http://localhost/xmlphp.php'));
                             treeLoader.addEventListener("complete",setTreeData);
                             
                        }
                        
                        protected function setTreeData(event:Event):void{
                             var dataXML:XML= XML(event.target.data);
                             
                             menutree.dataProvider=dataXML;
                             menutree.labelField="@label";
                             
                        }
              

               


              And here is the external xml file..

               

              <folder label="root">
                  <folder label="Childrenswear"></folder>
                  <folder label="Menswear">
                      <folder label="Sportswear">
                          <jpg label="Botttoms" /></folder>
                  </folder>
                  <folder label="Womenswear">
                      
                  </folder>
              </folder>
              

               

               


              So if the user clicks a button that says Menswear...How do i open up the menswear folder and display the nodes in it?

              • 4. Re: How to expand a tree to node where label ="String"
                aktell2007 Level 1

                Maybe this could help ! ?

                 

                <mx:Script>
                <![CDATA[
                               
                private function expandTreeNodes():void {
                                    
                     // One Only.
                     /* tree.validateNow();
                     tree.selectedIndex = 0; 
                     tree.expandChildrenOf(tree.selectedItem, true); */
                
                      // All.
                     tree.openItems = dp..gallery;
                }
                
                ]]>
                </mx:Script>
                
                • 5. Re: How to expand a tree to node where label ="String"
                  saisri2k2 Level 4

                  On click of the menswear button, the following function opens the menswer in the tree.

                   

                  protected function button1_clickHandler(event:MouseEvent):void
                                 {
                                      var expandXml:XML = XML(_xml.folder.(@label=='Menswear'));// here the logic is implementeod for the top level,  and searching for 'menswear' only. If you are trying to find out for the children then loop through the child elements after this line.
                                      menutree.expandItem(expandXml,true,true);
                                 }
                  
                  

                  <!--MXML-->
                  <s:Button label="Menswear" click="button1_clickHandler(event)"/>
                  <mx:Tree id="menutree" dataProvider="{_xml}" labelField="@label" showRoot="false" width="190" height="453" 
                                  itemClick="menutree_itemClickHandler(event)"></mx:Tree>
                  

                   

                            //xml data provider     
                                 [Bindable] private var _xml:XML = <folder label="root">
                                               <folder label="Childrenswear"></folder>
                                               <folder label="Menswear">
                                                   <folder label="Sportswear">
                                                       <jpg label="Botttoms" /></folder>
                                               </folder>
                                               <folder label="Womenswear">
                                                   
                                               </folder>
                                           </folder>;
                  

                   

                   

                   

                  P:S: please mark it as such.

                  • 6. Re: How to expand a tree to node where label ="String"
                    saisri2k2 Level 4

                    well.. adding to that , if you want to expand all the children of the men** , use