dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] 3 Tree Menus from 1 XML file

  1. #1
    Twansparant Twandeman's Avatar
    Join Date
    May 2004
    Location
    Amsterdam
    Posts
    197

    resolved [RESOLVED] 3 Tree Menus from 1 XML file

    Hi everyone,
    I'm starting to understand how to make flashcontent in XML,
    but I bumped into a problem, which is probably easy to solve, but I'm a bit lost...

    Here's what I'm trying to do:
    I have a movieclip which consists of 3 TreeMenu's, each of them needs to get populated from a single XML file. I have one Tree component in my library.

    First of all, I load the XML file like this:

    PHP Code:
    //Tree menu uit XML laden
    networkXML = new XML();
    networkXML.ignoreWhite true;
    networkXML.onLoad = function (success){
        if (
    success){
            
    tofillTree();
            
    tofillTreeClients();
            
    tofillTreeContacts();
        }
        else{
            
    trace("The XML could not be loaded");
        }
    }
    networkXML.load("content/content.xml"); 
    If the XML is loaded, 3 different functions are called, one for each Tree menu:

    PHP Code:
    function tofillTreeCommunities(){
        
    //Atach masters the component
        
    attachMovie("Tree""communities"1);
        
    //Properties
        
    communities.move(19,24);
        
    communities.setSize(140175);    
        
    //We filled the menu
        
    communities.dataProvider networkXML.firstChild.firstChild.firstChild.childNodes[0];
        
    //event objectss
        
    communities.addEventListener("change"listChanged);
    }

    listChanged = new Object();
    listChanged.change = function(evt_obj) {
        var 
    node evt_obj.target.selectedNode;
        
        
    //If it is a folder…
        
    if (communities.getIsBranch(node)){
            
    //If this is a branch, expand/collapse it.
            
    if (communities.getIsOpen(node)){
                
    communities.setIsOpen(nodefalsetrue);
            }
            
    //We opened it if this closed 
            
    else{
                
    communities.setIsOpen(nodetruetrue);
            }
        }
        
    //If it is a bond…
        
    else{
            
    getURL(node.attributes.dirurl"_blank");
        }

    PHP Code:
    function tofillTreeClients(){
        
    //Atach masters the component
        
    attachMovie("Tree""clients"1);
        
    //Properties
        
    clients.move(202,24);
        
    clients.setSize(140175);    
        
    //We filled the menu
        
    clients.dataProvider networkXML.firstChild.firstChild.firstChild.childNodes[1];
        
    //event objectss
        
    clients.addEventListener("change"listChanged);
    }

    listChanged = new Object();
    listChanged.change = function(evt_obj) {
        var 
    node evt_obj.target.selectedNode;
        
        
    //If it is a folder…
        
    if (clients.getIsBranch(node)){
            
    //If this is a branch, expand/collapse it.
            
    if (clients.getIsOpen(node)){
                
    clients.setIsOpen(nodefalsetrue);
            }
            
    //We opened it if this closed 
            
    else{
                
    clients.setIsOpen(nodetruetrue);
            }
        }
        
    //If it is a bond…
        
    else{
            
    getURL(node.attributes.dirurl"_blank");
        }

    PHP Code:
    function tofillTreeContacts (){
        
    //Atach masters the component
        
    attachMovie("Tree""contacts"1);
        
    //Properties
        
    contacts.move(384,24);
        
    contacts.setSize(200175);    
        
    //We filled the menu
        
    contacts.dataProvider networkXML.firstChild.firstChild.firstChild.childNodes[2];
        
    //event objectss
        
    contacts.addEventListener("change"listChanged);
    }

    listChanged = new Object();
    listChanged.change = function(evt_obj) {
        var 
    node evt_obj.target.selectedNode;
        
        
    //If it is a folder…
        
    if (contacts.getIsBranch(node)){
            
    //If this is a branch, expand/collapse it.
            
    if (contacts.getIsOpen(node)){
                
    contacts.setIsOpen(nodefalsetrue);
            }
            
    //We opened it if this closed 
            
    else{
                
    contacts.setIsOpen(nodetruetrue);
            }
        }
        
    //If it is a bond…
        
    else{
            
    getURL(node.attributes.dirurl"_blank");
        }

    The data for the Tree menu's is defined in the third level Childs of my XML file,
    so I have to use:

    communities.dataProvider = networkXML.firstChild.firstChild.firstChild.childN odes[0];
    clients.dataProvider = networkXML.firstChild.firstChild.firstChild.childN odes[1];
    contacts.dataProvider = networkXML.firstChild.firstChild.firstChild.childN odes[2];


    Right?

    This is my XML file:
    PHP Code:
    <?xml version="1.0" encoding="utf-8"?>

    <personal>

        <vision>
         Some text
        </vision>
        
        <work>
         Some text
        </work>
        
        <downloads>
            <nodo label = "Link1"  dirurl="link1.html" />
            <nodo label = "Link2"  dirurl="link2.html" />
        </downloads>
        
    </personal>

    <projects>
    </projects>

    <network>

        <communities>
            <nodo label = "Link1"  dirurl="link1.html" />
            <nodo label = "Link2"  dirurl="link2.html" />
        </communities>
        
        <clients>
            <nodo label = "Link1"  dirurl="link1.html" />
            <nodo label = "Link2"  dirurl="link2.html" />
        </clients>
        
        <contacts>
            <nodo label = "Link1"  dirurl="link1.html" />
            <nodo label = "Link2"  dirurl="link2.html" />
        </contacts>

    </network>
    Can anyone see what I'm doing wrong?
    I don't see it anymore.....

    Any help is very welcome!
    Thanks anyway.
    Toine Kamps | Design & Coding
    toinekamps.com

  2. #2
    Twansparant Twandeman's Avatar
    Join Date
    May 2004
    Location
    Amsterdam
    Posts
    197
    I got it!

    I modified my XML file like this:
    PHP Code:
    <?xml version="1.0" encoding="utf-8"?>

    <content>

    <personal>

        <vision>
         Some text
        </vision>
        
        <work>
         Some text
        </work>
        
        <downloads>
            <nodo label = "Link1"  dirurl="link1.html" />
            <nodo label = "Link2"  dirurl="link2.html" />
        </downloads>
        
    </personal>

    <projects>
    </projects>

    <network>

        <communities>
            <nodo label = "Link1"  dirurl="link1.html" />
            <nodo label = "Link2"  dirurl="link2.html" />
        </communities>
        
        <clients>
            <nodo label = "Link1"  dirurl="link1.html" />
            <nodo label = "Link2"  dirurl="link2.html" />
        </clients>
        
        <contacts>
            <nodo label = "Link1"  dirurl="link1.html" />
            <nodo label = "Link2"  dirurl="link2.html" />
        </contacts>

    </network>

    </content>
    And changed the parameters in my AS like this:

    communities.dataProvider = networkXML.firstChild.childNodes[2].childNodes[0];
    clients.dataProvider = networkXML.firstChild.childNodes[2].childNodes[1];
    contacts.dataProvider = networkXML.firstChild.childNodes[2].childNodes[2];
    Toine Kamps | Design & Coding
    toinekamps.com

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center