Go Back   CodingForums.com > :: Client side development > Flash & ActionScript > Adobe Flex

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-20-2011, 11:24 PM   PM User | #1
flexillu
New Coder

 
Join Date: Aug 2010
Posts: 89
Thanks: 3
Thanked 0 Times in 0 Posts
flexillu is an unknown quantity at this point
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
flexillu is offline   Reply With Quote
Old 02-09-2011, 10:32 PM   PM User | #2
iSynapps
New to the CF scene

 
Join Date: Jan 2011
Location: Germany
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
iSynapps is an unknown quantity at this point
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);
iSynapps is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:39 PM.


Advertisement
Log in to turn off these ads.