Hello
I was answering at a post from another forum, of the method of create a XML to take it into tree Component. It was not so easy at the beginning, cause the Tree compoent dont permit many options of XML structure, for exemple i cant have:
<africa><country label="abidjan"></country></africa>
<europe><country label="paris"></country></europe>
but:
<continent name="europe"><country label="berlin"></country></continent>
<continent name="north america"><country label="new york"></country></continent>
Here is the code:
var continent = new Array("Africa","America del sur");
var cityarray:Array = new Array()
obj = {ciudad:"paris", id:7}
cityarray.push(obj);
obj = {ciudad:"madrid", id:8}
cityarray.push(obj);
obj = {ciudad:"lisbao", id:8}
cityarray.push(obj);
tree.labelFunction = function(node) {
return node.nodeType == 1 ? node.nodeName : node.nodeValue;
};
var doc1:XML = new XML();
var doc2:XML;
for (var i:Number=0;i<continent.length;i++) {
// dont comment this line it will shut down your flash IDE
doc2 = new XML();
for (var j:Number=0;j<cityarray.length;j++) {
var nod3 = new XML("<ciudad id='"+cityarray[j].id+"'>"+cityarray[j].ciudad+"</ciudad>");
if (!doc2.firstChild.hasChildNodes) {
doc2 = new XML();
// var noderoot = new XML("<"+continent
+i+">"+nod3+"</"+continent+">")
var noderoot = new XML("<item name=\""+continent+"\">"+nod3+"</item>")
doc2.appendChild(noderoot);
}else{
doc2.firstChild.childNodes[0].appendChild(nod3)
}
}
if (!doc1.hasChildNodes()) {
doc1 = doc2;
}else{
doc1.firstChild.appendChild(doc2)
}
}
tree.dataProvider = doc1.toString();
you will see a commented line, cause my error it was to change the nodename at each level,
have a good week-end !