A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: XML menu with submenus issue

  1. #1
    Senior Member
    Join Date
    Apr 2006
    Posts
    431

    XML menu with submenus issue

    Hi all,
    I am trying to make an XML driven menu that supports submenus (one level only). Obviously not succeeding. I have been trying and testing all day long and nothing. If anybody can help me, I would be most greatful. I will pay for the lines of code needed, so please help.

    Here is the as2 code (well, the pseudo-code, because it doesn't work like it should)
    PHP Code:
    startPosY 20;
    startPosX 110;
    //btnWidth = 70
    var spacing=0
    var spacingsub=0
    //variable for laoding the first movie automatically
    var firstMovie:String  
    //load the XML 
    var MainMenuXml:XML = new XML();
    MainMenuXml.ignoreWhite true;
    var 
    movies:Array = new Array();
    var 
    names:Array = new Array();
    var 
    loadXMLS:Array = new Array();
    MainMenuXml.onLoad = function(status) {
        if (
    status) {
            var 
    linkname:Array = this.firstChild.childNodes;
            
    len linkname.length
            
            
    var linksub:Array = this.firstChild.childNodes[0].childNodes ;
            
    sublen linksub.length
            
    //sublen = sublink.length
             
    for (g=0g<subleng++) { 
                
    subnames=(linksub[g].attributes.menuName);
                 }
            for (
    i=0i<leni++) { 
                
    names.push(linkname[i].childNodes[0].attributes.menuName);
                
    movies.push(linkname[i].childNodes[0].attributes.loadModule);
                
    loadXMLS.push(linkname[i].childNodes[0].attributes.loadXML);

                
    _root.attachMovie("button","btn"+i,_root.getNextHighestDepth());
            
                
                
    _root["btns"+(i)].txt_btn_mc.nameTxt.autoSize "left"
                
    _root["btns"+(i)].txt_btn_mc.nameTxt.text = (namess[i]);

       
    _root["btn"+(i)].txt_btn_mc.nameTxt.autoSize "left"
       
    _root["btn"+(i)].txt_btn_mc.nameTxt.text = (names[i]);
                
    _root["btn"+i]._y startPosY;
                
    _root["btn"+i]._x spacing
                spacing 
    += _root["btn"+i]._width+20

                _root
    ["btn"+(i)].onRollOver btnOver;
                
    //onRollOut / onReleaseOutside
                
    _root["btn"+(i)].onRollOut _root["btn"+(i)].onReleaseOutside btnOut;
                
    //onRelease
                
    _root["btn"+(i)].onRelease btnReleased;

                


    import mx.transitions.Tween;
    import mx.transitions.*;
    import mx.transitions.easing.*;

    TransitionManager.start(_root["btn"+i], {type:Fadedirection:Transition.INduration:0.7easing:Regular.easeOut});


            }
        } else {
            
    errorTxt="Error Loading Menu"
        
    }
    };

    function 
    btnReleased () {
         
    _root.attachMovie("button","btns"+g,_root.getNextHighestDepth());
        
    _root["btns"+(g)].txt_btn_mc.nameTxt.autoSize "left"
       
    _root["btns"+(g)].txt_btn_mc.nameTxt.text = (subnames[g]);
                
    _root["btns"+g]._y startPosY+50;
                
    _root["btns"+g]._x spacingsub
                spacingsub 
    += _root["btns"+g]._width+20

    And this is the XML file

    PHP Code:
    <?xml version=”1.0” encoding=”UTF-8”?>

    <menu>
    <button>
       <menu menuName='Home' loadModule='home.swf' loadXML='home.xml' />
          <submenu menuName='our home' loadModule='home.swf' loadXML='home.xml' />
          <submenu menuName='hahaha' loadModule='home.swf' loadXML='home.xml' />
          <submenu menuName='vasilica' loadModule='home.swf' loadXML='home.xml' />
          <submenu menuName='hai la mure' loadModule='home.swf' loadXML='home.xml' />
    </button>
    <button>
       <menu menuName='About us' loadModule='home.swf' loadXML='home.xml' />
    </button>
    <button>
       <menu menuName='Services' loadModule='home.swf' loadXML='home.xml' />
    </button>
    </menu>
    The submenu should occur on btnReleased. Please help, in any you can.
    Thank you so much

    PS: I only wrote the code that is imoprtant for this issue, and left everything else behind

  2. #2
    Senior Member
    Join Date
    Apr 2006
    Posts
    431
    Anybody? A small idea?

  3. #3
    Twansparant Twandeman's Avatar
    Join Date
    May 2004
    Location
    Amsterdam
    Posts
    197
    Have you tried this?

    PHP Code:
    <menu>
    <
    button>
       <
    menu menuName='Home' loadModule='home.swf' loadXML='home.xml' >
          <
    submenu menuName='our home' loadModule='home.swf' loadXML='home.xml' />
          <
    submenu menuName='hahaha' loadModule='home.swf' loadXML='home.xml' />
          <
    submenu menuName='vasilica' loadModule='home.swf' loadXML='home.xml' />
          <
    submenu menuName='hai la mure' loadModule='home.swf' loadXML='home.xml' />
       </
    menu>
    </
    button>
    <
    button>
       <
    menu menuName='About us' loadModule='home.swf' loadXML='home.xml' />
    </
    button>
    <
    button>
       <
    menu menuName='Services' loadModule='home.swf' loadXML='home.xml' />
    </
    button>
    </
    menu
    Toine Kamps | Design & Coding
    toinekamps.com

  4. #4
    Senior Member
    Join Date
    Apr 2006
    Posts
    431
    Hi, thank you for answering . Practicly it's the same thing. Anyway, my problem is the actionscript, not the XML. That's where I'm going wrong

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