A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] Populate TreeMenu only with 1st and 2nd nodeLevels?

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

    resolved [RESOLVED] Populate TreeMenu only with 1st and 2nd nodeLevels?

    Hi everyone,

    I'm trying to make a dynamic TreeMenu which has to load a second TreeMenu from one single organised XML file....
    I was wundering if I can tell the TreeMenu only to load certain nodes or certain levels. Only the <node> parts of the XML file should fill the menu, everything beneath these nodes are only necessary for the next menu.

    This is what I got so far:

    PHP Code:
    Blokhoogte = new Tween (blokje,"_height",Regular.easeInOut,10,160,16,false);

    Blokhoogte.onMotionFinished = function() {
        
    Blokbreedte = new Tween (blokje,"_width",Regular.easeInOut,10,210,16,false);
        
        
    Blokbreedte.onMotionFinished = function() {
            
    //Tree menu uit XML laden
            
    shopXML = new XML();
            
    shopXML.ignoreWhite true;
            
    shopXML.onLoad = function(success) {
                if (
    success) {
                    
    tofillShop();
                } else {
                    
    trace("The XML could not be loaded");
                }
            };
            
    shopXML.load("content/content-test.xml");
        }
    };


    function 
    tofillShop() {
        
    //Atach masters the component    
        
    attachMovie("Tree","shop",1);
        
    shop.move(0,10);
        
    shop.vScrollPolicy "off";
        
    //Style Tree
        
    shop.rowHeight 20;
        
    //We filled the menu
        
    shop.dataProvider shopXML.firstChild.childNodes[4];
        
    shop.setSize(210,150);
        
    //event objects
        
    shop.addEventListener("change",listChanged);
    }

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

    PHP Code:
    function fill_jackets() {
        
    //Atach masters the component    
        
    attachMovie("Tree","jackets",1);
        
    jackets.move(230,5);
        
    jackets.vScrollPolicy "off";
        
    //We filled the menu
        
    jackets.dataProvider shopXML.firstChild.childNodes[4].childNodes[0].childNodes[0];
        
    //Auto height Tree
        
    var TreeHeight = (shopXML.firstChild.childNodes[4].childNodes[0].childNodes[0].childNodes.length)*18;
        
    jackets.setSize(105,TreeHeight);
        
    //event objects
        
    jackets.addEventListener("change",listChanged_J);

    With this XML file:

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

    <content>

        <collection>
            <fall2008 name="Vision"><bodytekst></bodytekst></fall2008>
            <summary name="Work"><bodytekst></bodytekst></summary>
        </collection>
        
        <bio></bio>
        
        <stockists></stockists>
        
        <contact></contact>
        
        <shop>
            <node label="COLLECTION">
                <node label="jackets" functie="fill_jackets">
                    <item label="'AMELIA' COTTON">
                    </item>
                    
                    <item label="'AMELIA' WOOL">
                    </item>
                    
                    <item label="'CATHERINE'">
                    </item>
                    
                    <item label="'JOSEPHINE'">
                    </item>
                    
                    <item label="'LUCY' COTTON">
                    </item>
                    
                    <item label="'LUCY' WOOL">
                    </item>
                    
                    <item label="'SAM' LEATHER">
                    </item>
                    
                    <item label="'VANESSA'">
                    </item>
                    
                </node>
            
                <node label="hats" functie="fill_hats">
                    <item label="Exhibition RACM">
                    </item>
                </node>
            </node>
            
            <node label="SIZING & PRODUCT INFORMATION" functie="fill_sizing">
            </node>
            
            <node label="TERMS & CONDITIONS OF SALE">
                <node label="pricing & payment" ></node>
                <node label="shipping & returns"></node>
            </node>
            
            <node label="ORDER FORM" functie="fill_orderform">
            </node>
                
        </shop>
        
        <press></press>
        
        <terms></terms>

    </content>
    My idea was to call a function that will load the next TreeMenu for 'jackets', but all the items in the jackets node are allready visible in the main TreeMenu.
    How can I tell the TreeMenu to stop filling the content between the <node></node> labels?

    So to be as clear as possible on this;
    A TreeMenu appears, when clicking 'COLLECTION' only 'jackets' and 'hats' should appear. When clicking 'jackets' a function gets called. This function makes a new seperate TreeMenu which will load everything between the 'jackets' node.

    Is this possible? And if so, how?
    Any help is very much appreciated!
    Toine Kamps | Design & Coding
    toinekamps.com

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe you can adapt this to what you are trying to do...

    Code:
    function tofillShop() {
    	//Atach masters the component     
    	attachMovie("Tree", "shop", 1);
    	shop.move(0, 10);
    	shop.vScrollPolicy = "off";
    	//Style Tree 
    	shop.rowHeight = 20;
    	//We filled the menu 
    	shop.dataProvider = shopXML.firstChild.childNodes[4];
    	shop.setSize(210, 150);
    	//event objects 
    	shop.addEventListener("nodeOpen", listChanged);
    	shop.addEventListener("change", listChanged);
    }
    listChanged = new Object();
    listChanged.nodeOpen = checkLevel;
    listChanged.change = isChanged;
    //
    function checkLevel(evt_obj) {
    	var anode = evt_obj.target.eventPending;
    	if (anode.attributes.functie != undefined) {
    		shop.setIsOpen(anode, false, false);
    	}
    }
    function isChanged(evt_obj) {
    	var anode = evt_obj.target.selectedNode;
    	if (anode.attributes.functie == undefined) {
    		if (shop.getIsBranch(anode)) {
    			//If this is a branch, expand/collapse it. 
    			if (shop.getIsOpen(anode)) {
    				shop.setIsOpen(anode, false, true);
    			} else {
    				//We opened it if this closed 
    				shop.setIsOpen(anode, true, true);
    			}
    		}
    	} else {
    		trace(anode.attributes.functie);
    	}
    }
    Only tested in MX2004.

  3. #3
    Twansparant Twandeman's Avatar
    Join Date
    May 2004
    Location
    Amsterdam
    Posts
    197
    Wow! Thanks dawsonk, this is awesome!
    I didn't had to adjust it at all, this is exactly what I needed! Many thanks!
    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