17 Replies Latest reply on Jul 5, 2009 6:11 PM by kglad

    XML flash Menu

    beko75

      Hello Guys,

       


      I am stuck with a xml flash menu which contains quite a few great options to manipulate the text, url, button and even change the color to the menu externally from xml. The only thing missing here (which I massively need it) is the option resizing the buttons from the xml file itself. The buttons need to be resized so that they fit each text length. I have the feeling that someone that is good at XML and deal with ActionScript would be able to easily add this option.

       


      Thanks for commiting your time on this and I would be happy to help anyone in return who tackles this requirement I am after now.

       


      Please download the file attached and you can own it as well.

       


      Looking forward to hearing from you soon.

       


      Respectfully yours,

       

      Beko

        • 1. Re: XML flash Menu
          kglad Adobe Community Professional & MVP

          you can easily get help here but, it's less likely someone will do your work for you.  and it's not possible when there's no file attached.

           

          post your xml code and the xml parsing actionscript.

          • 2. Re: XML flash Menu
            beko75 Level 1

            Thanks for your quick reply,

             

            I attached the file but it seems it didn't go through. Please download the file from the link below:

             

            http://galaboutique.ch/beko/menu.zip

             

            Again, profuse thanks for your efforts.

             

            Beko

            • 3. Re: XML flash Menu
              kglad Adobe Community Professional & MVP

              maybe that was unclear. paste your xml code and the xml parsing actionscript here.

              • 4. Re: XML flash Menu
                beko75 Level 1

                Ok, here we go:

                 

                 

                 

                ACTION SCRIPT CODE:


                _parent._visible = false;
                // xml processing
                menu_cfg_xml = new XML();
                menu_cfg_xml.load(String(_url.slice(0, (_url.length-3)))+"xml");
                menu_cfg_xml.ignoreWhite = 1;
                //
                menu_cfg_xml.onLoad = function(ok) {
                    // create main menu after successful loading of XML
                    if (ok) {
                        create_menu();
                    } else {
                        trace("XML not loaded");
                    }
                };
                //
                counter = 1;
                function create_menu() {
                    while (counter<menu_cfg_xml.firstChild.childNodes.length) {
                        attachMovie("button_type", "btn"+counter, counter);
                        set("btn"+counter+"._x", counter*80-100);
                        btn1._y = 0;
                        // set the buttons text
                        set("btn"+counter+".the_text", menu_cfg_xml.firstChild.childNodes[counter].attributes.text);
                        set("btn"+counter+".the_url", menu_cfg_xml.firstChild.childNodes[counter].attributes.url);
                        set("btn"+counter+".the_target", menu_cfg_xml.firstChild.childNodes[counter].attributes.target);
                        this["btn"+counter].onRollOver = this["btn"+counter].onDragOver=function () {
                            this.effect.gotoAndPlay(2);
                            this.textul1.textColor = "0x"+menu_cfg_xml.firstChild.childNodes[0].attributes.text_color2;
                        };
                        this["btn"+counter].onRollOut = this["btn"+counter].onDragOut=function () {
                            this.textul1.textColor = "0x"+menu_cfg_xml.firstChild.childNodes[0].attributes.text_color1;
                            this.effect.gotoAndPlay(9);
                        };
                        this["btn"+counter].onRelease = function() {
                            if (this.the_url != undefined and this.the_url != "") {
                                getURL(this.the_url, this.the_target);
                            }
                        };
                        //set buttons color
                        this["button_color"+counter] = new Color("btn"+counter+".btn_color");
                        this["button_color"+counter].setRGB("0x"+menu_cfg_xml.firstChild.childNodes[0].attributes .button_color);
                        //set button effect color
                        this["effect_color"+counter] = new Color("btn"+counter+".effect");
                        this["effect_color"+counter].setRGB("0x"+menu_cfg_xml.firstChild.childNodes[0].attributes .effect_color);
                        //set button text color
                        this["btn"+counter].textul1.textColor = "0x"+menu_cfg_xml.firstChild.childNodes[0].attributes.text_color1;
                        counter++;
                    }
                    _parent._visible = true;
                    info_clip._visible = false;
                }

                 

                 

                 

                 

                >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

                 

                XML CODE:

                 

                 

                <?xml version="1.0" encoding= "UTF-8" ?>
                <!-- Menu created by www.adrianTNT.com -->
                <menu>

                 

                <options button_color="000066" effect_color="87A10C" text_color1="87A10C" text_color2="FFFFFF">
                </options>

                 

                <button text="Task force" url="http://www.google.com" target="_parent">width="250" height="136"</button>
                <button text="Service og turisme" url="http://www.google.com" target="_parent"></button>
                <button text="Fodbold" url="http://www.google.com" target="_parent"></button>
                <button text="Idraet" url="http://www.google.com" target="_parent"></button>
                <button text="Kunst and Design" url="http://www.google.com" target="_parent"></button>
                <button text="Teknisk/praktisk linje" url="http://www.google.com" target="_parent"></button>
                <button text="Gastronomi" url="http://www.google.com" target="_parent"></button>
                <button text="Laekker mad" url="http://www.google.com" target="_parent"></button>
                <button text="Musik" url="http://www.google.com" target="_parent"></button>
                <button text="Turbo-boglig" url="http://www.google.com" target="_parent"></button>

                 

                </menu>

                • 5. Re: XML flash Menu
                  kglad Adobe Community Professional & MVP

                  i don't see where you're assigning text (the_text) to your movieclip button's textfield (textul1).

                   

                  but once you get that fixed you can assign each button's textfield to autoSize="left", and then assign the buttons background (converted to a movieclip) to have the same width as the autoSized  textfield.

                  • 6. Re: XML flash Menu
                    beko75 Level 1

                    Hi kglad,

                     

                    Thanks for your efforts on providing help but unfortunately I do not quite understand your explantion. Are you able to modify those script I sent and send back, I might better understand that way I guess.

                     

                    Thanks again.

                     

                    Beko

                    • 7. Re: XML flash Menu
                      kglad Adobe Community Professional & MVP

                      are you seeing text assigned to your button's textfield?

                      • 8. Re: XML flash Menu
                        kglad Adobe Community Professional & MVP


                        _parent._visible = false;
                        // xml processing
                        menu_cfg_xml = new XML();
                        menu_cfg_xml.load(String(_url.slice(0, (_url.length-3)))+"xml");
                        menu_cfg_xml.ignoreWhite = 1;
                        //
                        menu_cfg_xml.onLoad = function(ok) {
                            // create main menu after successful loading of XML
                            if (ok) {
                                create_menu();
                            } else {
                                trace("XML not loaded");
                            }
                        };
                        //
                        counter = 1;
                        function create_menu() {
                            while (counter<menu_cfg_xml.firstChild.childNodes.length) {
                                attachMovie("button_type", "btn"+counter, counter);
                                set("btn"+counter+"._x", counter*80-100);
                                btn1._y = 0;
                                // set the buttons text
                             //   set("btn"+counter+".the_text", menu_cfg_xml.firstChild.childNodes[counter].attributes.text);

                        this["btn"+counter].the_text= menu_cfg_xml.firstChild.childNodes[counter].attributes.text;
                        this["btn"+counter].the_text.autoSize="left";
                        // and if there's a background graphic in this["btn"+counter] assign its width  equal to the width of this["btn"+counter].the_text


                                set("btn"+counter+".the_url", menu_cfg_xml.firstChild.childNodes[counter].attributes.url);
                                set("btn"+counter+".the_target", menu_cfg_xml.firstChild.childNodes[counter].attributes.target);
                                this["btn"+counter].onRollOver = this["btn"+counter].onDragOver=function () {
                                    this.effect.gotoAndPlay(2);
                                    this.textul1.textColor = "0x"+menu_cfg_xml.firstChild.childNodes[0].attributes.text_color2;
                                };
                                this["btn"+counter].onRollOut = this["btn"+counter].onDragOut=function () {
                                    this.textul1.textColor = "0x"+menu_cfg_xml.firstChild.childNodes[0].attributes.text_color1;
                                    this.effect.gotoAndPlay(9);
                                };
                                this["btn"+counter].onRelease = function() {
                                    if (this.the_url != undefined and this.the_url != "") {
                                        getURL(this.the_url, this.the_target);
                                    }
                                };
                                //set buttons color
                                this["button_color"+counter] = new Color("btn"+counter+".btn_color");
                                this["button_color"+counter].setRGB("0x"+menu_cfg_xml.firstChild.childNodes[0]. attributes.button_color);
                                //set button effect color
                                this["effect_color"+counter] = new Color("btn"+counter+".effect");
                                this["effect_color"+counter].setRGB("0x"+menu_cfg_xml.firstChild.childNodes[0]. attributes.effect_color);
                                //set button text color
                                this["btn"+counter].textul1.textColor = "0x"+menu_cfg_xml.firstChild.childNodes[0].attributes.text_color1;
                                counter++;
                            }
                            _parent._visible = true;
                            info_clip._visible = false;
                        }

                         

                         

                         

                         


                        • 9. Re: XML flash Menu
                          beko75 Level 1

                          kglad,

                           

                          Thanks for dedicating your time to this.

                          I realized you have interpolated the following code in the action script:

                           

                           

                          menu_cfg_xml.firstChild.childNodes[counter].attributes.text);

                          this["btn"+counter].the_text= menu_cfg_xml.firstChild.childNodes[counter].attributes.text;
                          this["btn"+counter].the_text.autoSize="left";
                          // and if there's a background graphic in this["btn"+counter] assign its width  equal to the width of this["btn"+counter].the_text

                           

                           

                           

                           

                          What we are missing now is that how can I change the size for each button from the XML? At this juncture, the size should be relative (rather than absolute) so that it fits in each text length? Please check the XML code above again to see how it interacts with flash texts, color, button, url etc so that it gives you an idea on how to add the resizing script for each button.

                          This is the only step we are missing and that's gonna be it I guess

                           

                          Tons of thanks for your contribution on this.

                           

                          Beko

                          • 10. Re: XML flash Menu
                            kglad Adobe Community Professional & MVP

                            you don't need to set the size in the xml.  the actionscript i gave you will automatically size the button so it fits the text.  read my comment in the code i supplied.

                            • 11. Re: XML flash Menu
                              beko75 Level 1

                              Hi again kglad,

                               

                              You have been the best I have ever received any helps onnline so far and I am excessively appreciate your patience.

                               

                              By the way, your extra added script was very self-explanatory and I totally understood what you meant by it, but unfortunately it still doesn't automatically adjust the button size based on text length. Any idea?

                               

                              That's why I sent you the link to download the source files so that you can make sure it works 100% on your end as well whenever you apply any changes to the script there to make it work properly.

                               

                               

                               

                              Thanks,

                              Beko

                              • 12. Re: XML flash Menu
                                kglad Adobe Community Professional & MVP

                                show your updated code that resizes the button based on the width of the button's textfield.

                                • 13. Re: XML flash Menu
                                  beko75 Level 1

                                  Kglad,

                                   

                                  Can we go with a little simplier code that I ran into? I have another flash menu where the text is pulled from the xml file. The only thing I need modified here is to be able to add URL to the link of the menu. You will see below on the XML CODE the name of the link is SERVICE.

                                   

                                  Please check the scripts below:

                                   

                                   

                                   

                                  ACTION SCRIPT CODE:

                                   

                                  function loadXML(loaded) {
                                      if (loaded) {
                                          _root.inventor = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
                                          service.text = _root.inventor;
                                      } else {
                                          content = "file not loaded!";
                                      }
                                  }
                                  xmlData = new XML();
                                  xmlData.ignoreWhite = true;
                                  xmlData.onLoad = loadXML;
                                  xmlData.load("/menu/service.xml");

                                   

                                   

                                  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

                                   

                                   

                                  XML CODE:

                                   

                                   

                                   

                                  <?xml version="1.0"?>

                                   

                                  <inventors>

                                   

                                  <person>
                                          <service>Service</service>
                                     
                                  </person>

                                   

                                  </inventors>

                                   

                                   

                                  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                                   

                                   

                                   

                                  I tried adding something like this but it wasn't working:


                                     
                                          <task="Service" ref="service.html"/>

                                   

                                   

                                   

                                   

                                  Please let me knwo if you can handle this.

                                   

                                  Thanks in advance.

                                   

                                  Beko

                                  • 14. Re: XML flash Menu
                                    kglad Adobe Community Professional & MVP

                                    what's the relationship between your last message and anything else in this thread?

                                    • 15. Re: XML flash Menu
                                      beko75 Level 1

                                      Apologies as I had to get rid of the previous XML menu functionality and deal with the preliminary one I sent to you as that is the appropriate code I am after which is only missing the URL to be added to a link.

                                      Please help me on this as the time is CRITICAL which I need it by tomorrow for my school project, otherwise I am dead

                                       

                                      Please review the AS CODE as well as the XML code and modify it for me to add a URL to the link "Service" from the XML itself.

                                       

                                      I am sure you can do this as I found your skills pretty advanced.

                                       

                                      Thanks again and looking forward to hearing from you veery soon.

                                       

                                      Beko

                                      • 16. Re: XML flash Menu
                                        beko75 Level 1

                                        Bu the way "kglad",

                                         

                                        I posted a new thread labelled "Add URL to XML Flash Menu" if you want that to answer through the new thread.

                                         

                                        Thanks so much,

                                        Beko

                                        • 17. Re: XML flash Menu
                                          kglad Adobe Community Professional & MVP

                                          close this thread down then.  you should mark 8 as correct.

                                          1 person found this helpful