10 Replies Latest reply on Dec 12, 2011 5:10 PM by armandix

    how can I do to each Node declared a "menu" show all its children nodes in a dynamic way?

    armandix Level 1

      I develop a piece of code that brings me to an xml, all Nodes i use this code:

       

      for(var i=0; i< menu_xml.childNodes.length; i++){



      corrent_node = menu_xml.childNodes[i].length;


      corrent_item.action = corrent_node.attributes.action;


      corrent_item.variables = corrent_node.attributes.variables;


      corrent_item.name.text = corrent_node.attributes.name;


      The following xml is returned

       

      <menu name='Autonomous Photovoltaic Systems'>

           <item name='Autonomus Photovoltaic Systems' action='' variables='SI-SIA'/>

      </menu>

      <menu name='Indoor lighting'>

           <item name='LED 10W' action='' variables='IN-LED'/>

           <item name='LED 3W' action='' variables='IN-LED'/>

           <item name='LED 6W' action='' variables='IN-LED'/>

      </menu>...


       

      What I need is for each of the nodes highlighted in green to return the child Nodes.

      Example: when I move the mouse over the menu Indoor lighting, the results should be: Indoorlighting | LED 10W> 3W LED> LED 6W

        • 1. Re: how can I do to each Node declared a "menu" show all its children nodes in a dynamic way?
          kglad Adobe Community Professional & MVP

          you should be using something like the following to define corrent_node.  it's not clear what the other left-sides of the assignment operators are.

           

           

          for(var i=0; i< menu_xml.childNodes.length; i++){

           


          corrent_node = menu_xml.childNodes[i].firstChild;


          corrent_item.action = corrent_node.attributes.action;


          corrent_item.variables = corrent_node.attributes.variables;

          corrent_item.name.text = corrent_node.attributes.name;
          }


           

          1 person found this helpful
          • 2. Re: how can I do to each Node declared a "menu" show all its children nodes in a dynamic way?
            armandix Level 1

            Kglad can you help me with this ? I can not do.

             

            First I call the Main Nodes with this code

            where do I add a movieclip and give him a position, in x and y then I compare the attributes with my variables

            for(var i=0; i< menu_xml.childNodes.length; i++){

            corrent_item = corrent_menu.attachMovie("menuit","menu"+i+"_mc", i);

                                corrent_item._x = x + i*corrent_item._width;

                                corrent_item._y = y;

                                //properties from the XML

                                corrent_node = menu_xml.childNodes[i];

                                corrent_item.action = corrent_node.attributes.action;

                                corrent_item.variables = corrent_node.attributes.variables;

                                corrent_item.name.text = corrent_node.attributes.name;


            Now that I set for each nodename equal "menu"

             

             

            if (menu_xml.childNodes[i].nodeName == "menu"){

             

            this is my problem Kglad how do I load the nodes of each "menu" please help me!!

             

             

            }

            • 3. Re: how can I do to each Node declared a "menu" show all its children nodes in a dynamic way?
              kglad Adobe Community Professional & MVP

              for(var i=0; i< menu_xml.childNodes.length; i++){

              corrent_item = corrent_menu.attachMovie("menuit","menu"+i+"_mc", i);

                                  corrent_item._x = x + i*corrent_item._width;

                                  corrent_item._y = y;

                                  //properties from the XML

                                  corrent_node = menu_xml.childNodes[i];

                          

                                  corrent_item.name.text = corrent_node.attributes.name;

              for(var j:Number=0;j<corrent_node.childNodes.length;j++){

              trace(corrent_node.childNodes[j].attributes.name);

              }

              }


              • 4. Re: how can I do to each Node declared a "menu" show all its children nodes in a dynamic way?
                armandix Level 1

                Kglad

                I changed the code, using that one you sent me


                for(var i=0; i< menu_xml.childNodes.length; i++){

                                    //um movie clip para cada item de menu

                 

                                    //attacheMovie(agrega o movieclip da livraria, novo nome dado pelo utilizador, ++ incremento);

                                    corrent_item = corrent_menu.attachMovie("menuit","menu"+i+"_mc", i);

                                    corrent_item._x = x + i*corrent_item._width;

                                    corrent_item._y = y;

                                    // propriedades provenientes do XML

                                    corrent_node = menu_xml.childNodes[i];

                                    corrent_item.action = corrent_node.attributes.action;

                                    corrent_item.variables = corrent_node.attributes.variables;

                                    corrent_item.name.text = corrent_node.attributes.name;

                 

                 

                                    for(var j:Number=0;j<corrent_node.childNodes.length;j++){

                 

                                    //open a submenu

                                              corrent_item.node_xml = corrent_node.childNodes[j].attributes.name;

                                              corrent_item.onRollOver = corrent_item.onDragOver  = function(){

                                              /*submenu positions */

                 

                 

                                              var px = this._x;

                                              var py = this._y + this._height +2;

                                               trace(corrent_menu);

                                               trace(corrent_item);

                                              //generate submenu

                                              gerar_menu(corrent_menu, "submenu_mc", px, py, 1000, this.menu_xml);

                                              var cor =new Color(this.background);

                                              cor.setRGB(0x767676);

                                    };

                }

                 

                But when I call the nodes children, he continues to make the same error reproduce de same main menu many times

                what I wanted was for each of the main menu items, call the child Nodes

                • 5. Re: how can I do to each Node declared a "menu" show all its children nodes in a dynamic way?
                  kglad Adobe Community Professional & MVP

                  i showed how to parse your xml.

                   

                  but i don't know everything else you're trying to do and from the looks of the code you've posted, and your lack of explanation, i think someone will need to download your source files and correct them for you.

                  • 6. Re: how can I do to each Node declared a "menu" show all its children nodes in a dynamic way?
                    armandix Level 1

                    Kglad if I send you the files you fix them myself?

                    • 7. Re: how can I do to each Node declared a "menu" show all its children nodes in a dynamic way?
                      kglad Adobe Community Professional & MVP

                      i don't download and fix files unless i'm hired.

                       

                      free help i only offer via the adobe forums.

                      • 10. Re: how can I do to each Node declared a "menu" show all its children nodes in a dynamic way?
                        armandix Level 1

                        this post is solved,

                        if someone need the code plese contact me