Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2010
    Posts
    89
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Post Using a Tree component as a menu...advice needed

    Been struggling with this for a while now, and the official forums are useless.

    Basically, i have a hierarchical data problem i'm trying to use a Tree to solve. It's categories of clothing. So items have a gender, category, type and variation:

    e.g:

    Menswear, Trousers, Chinos, Slimfit.

    This is stored in a database and i have a script that goes through and works out which item is a parent of what, checks if its a file or folder and i end i[ with XML like so:

    Code:

    Code:
    <folder label="root">
         <folder label="Menswear">
              <folder label="Sportswear">
                   <folder label="Tops">
                      <item label="Crew neck"/>
                   </folder>
                        <folder label="Bottoms">
                      <item label="Joggers"/>
                   </folder>
              </folder>
         </folder>
    </folder>
    Firstly Is this XML anygood for the purpose i need?Is it silly to have nodes with just labels and no data?

    Ok so i set this XML as the dataprovider of a tree using these functions in flex:

    Code:

    Code:
    protected function loadTreeData():void{
    
         var treeLoader:URLLoader = new URLLoader(newURLRequest('SCRIPTNAME'));
    
    treeLoader.addEventListener("complete",setTreeData);
    			
    		}
    		
    protected function setTreeData(event:Event):void{
    	var dataXML:XML= XML(event.target.data);
    		
    	menutree.dataProvider=dataXML;
    	menutree.labelField="@label";
    			
    		
    }
    Secondly Is This the correct way to do this?

    Ok so then when a tree item is clicked i want to Get the path to the selected item. So if the users drills down through the above example and clicks Slimfit i want to get the path to that item.

    e.g params["A"]=Menswear
    params["B"]=Trousers
    params["C"]=Chinos
    params["D"]=Slimfit.

    However this is where i am struggling, this is what i have so far:

    Code:

    Code:
    var params:Array = new Array();
    				
    	var lastNode:Object = tree.selectedItem.@label;
    				
    	while (lastNode)
    					
    	{
    					
    	     params.unshift(lastNode.@label);
    					
    	     lastNode = lastNode.parent()[0];
    					
    	}
    I have tried it with

    var lastNode:XML = tree.selectedItem.@label; but nothing seems to work.

    Any help will be greatly appreciated! of any part of this.

    Thanks a lot

  • #2
    New to the CF scene
    Join Date
    Jan 2011
    Location
    Germany
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you want to work with the items on your XML, you should do this
    Code:
    LIST
    <?xml version="1.0" encoding="utf-8"?>
    <list>
      <folder label="Men">
        <subfolder label="Top">
          <item label="some title" id="00XXX" size="90".../>
        </subfolder>
      </folder>
    </list>
    
    EVENT.COMPLETE
    var result:XMLList = new XMLList(XML(e.target.data)..folder);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •