A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] How to acces childNodes in Tree node?

Hybrid View

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

    resolved [RESOLVED] How to acces childNodes in Tree node?

    Hi everyone,

    I'm building my first one-framed dynamic XML website, which can be updated using this FlashXMLeditor.
    All of my content gets populated from 1 XML file.

    One of the submenu's is a Tree component with several buttons (=nodes).
    When pressing one of these nodes of this Tree, I want to show some detailed information (text) and load several images of the selected node.
    How do I do this???

    The Tree itself gets populated correctly, but the changeListener doesn't work.
    I don't want to use node.attributes because then the XMLeditor doesn't work for me.

    This is my AS so far:

    PHP Code:
    //Tree menu uit XML laden
    graphicXML = new XML();
    graphicXML.ignoreWhite true;
    graphicXML.onLoad = function (success){
        if (
    success){
            
    tofillTreeGraphicdesign();
        }
        else{
            
    trace("The XML could not be loaded");
        }
    }
    graphicXML.load("content/content-test.xml");


    function 
    tofillTreeGraphicdesign(){
        
    graphicdesign.vScrollPolicy "off";
        
    graphicdesign.rowHeight 18;
        
    graphicdesign.setStyle("fontSize"8);
        
    graphicdesign.setStyle("fontFamily""Bavaria Regular");
        
    graphicdesign.setStyle("fontWeight""normal");
        
    graphicdesign.embedFonts true;
        
    graphicdesign.setStyle("selectionColor"0xFFFFFF);
        
    graphicdesign.setStyle("textSelectedColor"0x000000);
        
    //We filled the menu
        
    graphicdesign.dataProvider graphicXML.firstChild.childNodes[1].childNodes[0];
        
    //event objectss
        
    graphicdesign.addEventListener("change"listChanged);
    }

    listChanged = new Object();
    listChanged.change = function(evt_obj) {
        var 
    node evt_obj.target.selectedNode;
        
    //If it is a folder…
        
    if (graphicdesign.getIsBranch(node)){
            
    //If this is a branch, expand/collapse it.
            
    if (graphicdesign.getIsOpen(node)){
                
    graphicdesign.setIsOpen(nodefalsetrue);
            }
            
    //We opened it if this closed 
            
    else {
                
    graphicdesign.setIsOpen(nodetruetrue);
            }
        }
        
    //If it is a bond…
        
    else {
            
    test._visible false;
            
            var 
    Client node.childNodes[0];
            var 
    Year node.childNodes[1];
            var 
    Medium node.childNodes[2];
            var 
    Desc node.childNodes[3];
            var 
    Img node.childNodes[4];
            
            
    client.text Client;
            
    year.text Year;
            
    medium.text Medium;
            
    description.xmltext.text Desc;
            
    loadMovie(Img"_root.picholder");
        }

    And my XML file:

    PHP Code:
    <?xml version="1.0" encoding="utf-8"?>

    <content>

        <personal>
            
            <vision name="Vision">
                <bodytekst>Tekst voor Vision
                </bodytekst>
             </vision>
             
             <work name="Work">
                 <bodytekst>Tekst voor Work</bodytekst>
             </work>
             
             <downloads name="Downloads">
                 <node label="Download 1" dirurl="download1.pdf" />
             </downloads>
             
        </personal>
             
        <projects>
             
             <graphic name="Graphic design">
             
                 <node label="Graphic 1">
                     <client>Client</client>
                     <year>2007</year>
                     <medium>website</medium>
                     <desc>Omschrijving</desc>
                     <image>images/image_1.jpg</image>
                 </node>
             
             </graphic>
             
             <spatial name="Spatial design">
                <node label="Spatial 1"/>
             </spatial>
             
             <other name="Other works">
                 <node label="Other work 1"/>
             </other>
        
        </projects>
        
        <network>
        
            <communities name="Communities">
                <node label="community 1" dirurl="http://www.domain.nl" />
            </communities>
            
            <clients name="Clients">
                <node label="client 1" dirurl="http://www.domain.nl" />
            </clients>
            
            <contacts name="Contacts">
                <node label="contact 1" dirurl="http://www.domain.nl" />
            </contacts>
        
        </network>
        
    </content>
    Could someone please push me in the right direction?
    I tried using a seperate .as file to load mx.controls.tree, but I can't figure out how that works.

    I could really use some help, because I'm on a deadline ont his project.
    Many many thanks!
    Toine Kamps | Design & Coding
    toinekamps.com

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    but the changeListener doesn't work

    move the event listener out of the tofillTreeGraphicdesign function -

    listChanged = new Object();
    listChanged.change = function(evt_obj) {
    <snip>
    };
    graphicdesign.addEventListener("change", listChanged);

  3. #3
    Twansparant Twandeman's Avatar
    Join Date
    May 2004
    Location
    Amsterdam
    Posts
    197
    Yes! That's it! Wow...

    However, the values in the textboxes appear with the <client>Client</client>, instead of just Client.
    Do you know what's causing that?

    PHP Code:
    function tofillTreeGraphicdesign(){
        
    graphicdesign.vScrollPolicy "off";
        
    graphicdesign.rowHeight 18;
        
    graphicdesign.setStyle("fontSize"8);
        
    graphicdesign.setStyle("fontFamily""Bavaria Regular");
        
    graphicdesign.setStyle("fontWeight""normal");
        
    graphicdesign.embedFonts true;
        
    graphicdesign.setStyle("selectionColor"0xFFFFFF);
        
    graphicdesign.setStyle("textSelectedColor"0x000000);
        
    //We filled the menu
        
    graphicdesign.dataProvider graphicXML.firstChild.childNodes[1].childNodes[0];
    }

    listChanged = new Object();
    listChanged.change = function(evt_obj) {
        var 
    node evt_obj.target.selectedNode;
        
    //If it is a folder…
        
    if (graphicdesign.getIsBranch(node)){
            
    //If this is a branch        
            
    var Client node.childNodes[0];
            var 
    Year node.childNodes[1];
            var 
    Medium node.childNodes[2];
            var 
    Desc node.childNodes[3];
            var 
    Img node.childNodes[4];
            
            
    client.text Client;
            
    year.text Year;
            
    medium.text Medium;
            
    description.xmltext.text Desc;
            
    loadMovie(Img"_root.picholder");
        }
        else {
        }
    };
    //event objects
    graphicdesign.addEventListener("change"listChanged); 
    Thank you for your time modified dog!
    Appreciate it!
    Toine Kamps | Design & Coding
    toinekamps.com

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    have you tried -
    var Client = node.childNodes[0].firstChild;

  5. #5
    Twansparant Twandeman's Avatar
    Join Date
    May 2004
    Location
    Amsterdam
    Posts
    197
    Once again you're right! Thanks!
    Toine Kamps | Design & Coding
    toinekamps.com

  6. #6
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    you're welcome

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