Welcome, Guest. Please login or register.
Did you miss your activation email?
05/21/12, 04:00
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  V2 Components (Flash MX 2004 - Flash 8) (Moderators: vesa kortelainen, Ronald Wernecke, Jorge Solis, ..:: Mazhar Hasan ::.., papachan)
| | |-+  loading XML into treeComponent without XML
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: loading XML into treeComponent without XML  (Read 1078 times)
papachan
Moderator
Systems Administrator
*****
Posts: 507


View Profile WWW
« on: 12/02/05, 16:33 »

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,  Smiley  have a good week-end !
Logged

Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!