...

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

flexillu
01-20-2011, 11:24 PM
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:

<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:

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:

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

iSynapps
02-09-2011, 10:32 PM
If you want to work with the items on your XML, you should do this

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);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum