9 Replies Latest reply on Jul 30, 2009 6:22 AM by kglad

    italic text from xml file to create dynamic menu

    wwscoper

      Hi,

       

      I have a working menu that pulls in data from an XML file. The movie clips are attached to the stage dynamically based on the number of XML items. I need most of the text formatted regularly, but one button requires some html formatted text. (italics). I've set the text box in Flash to html = true.

       

      Here is some of my code:

       

      tl["btn"+(i)].blackTxt.Txt.html = true;

      tl["btn"+(i)].whiteTxt.Txt.html = true;

      //Place the button name from names Array into the blackTxt text box

      tl["btn"+(i)].blackTxt.Txt.htmlText = (names[i]);

      //Place the button name from names Array into the whiteTxt text box

      tl["btn"+(i)].whiteTxt.Txt.htmlText = (names[i]);

       

      //XML

      <BUTTON LINK='http://www.website.com/'><![CDATA[text here <i>italics here</i> text here]]></BUTTON>

       

      When it shows up in Flash, I can see the <i> tags and none of the text is formatted in italics.

       

      Any ideas? Thanks for the help.

        • 1. Re: italic text from xml file to create dynamic menu
          kglad Adobe Community Professional & MVP

          use the firstChild.nodeValue to assign names

          • 2. Re: italic text from xml file to create dynamic menu
            wwscoper Level 1

            I may not have provided enough context. Here is more of the code:

             

            myXML.onLoad = function(){

            //Set varible to store the XML childNodes

            //This allows you to get the number of buttons in the XML file.

            //You'll use this tell flash how many times to loop the for loop.

            var linkname:Array = this.firstChild.childNodes;

            //Set a for loop

            for(i=0;i<linkname.length;i++){

            //Push the button name into the names Array

            if (linkname[i].attributes.NAME) {

            names.push(linkname[i].attributes.NAME);

            }

            else {

            names.push(linkname[i]);

            }

            //Push the button link into the links Array

            links.push(linkname[i].attributes.LINK);

            //Attach the button Movie Clip from the libray give it an instance name and place it on the next highest level

            tl.attachMovie("button","btn"+i,tl.getNextHighestDepth());

            //Set the y position of the buttons

            tl["btn"+i]._y = yPosition;

            //Increace the varible yPosition 15 pixel each time the loop runs to place each button under each other

            yPosition = yPosition + 18;

             

            //set text to html text

            tl["btn"+(i)].blackTxt.Txt.html = true;

            tl["btn"+(i)].whiteTxt.Txt.html = true;

            //Place the button name from names Array into the blackTxt text box

            tl["btn"+(i)].blackTxt.Txt.htmlText = (names[i]);

            //Place the button name from names Array into the whiteTxt text box

            tl["btn"+(i)].whiteTxt.Txt.htmlText = (names[i]);

            //Assign the btnOver function to the button onRollOver state.

            tl["btn"+(i)].onRollOver = btnOver;

            //Assign the btnOut function to the button onRollOut state.

            tl["btn"+(i)].onRollOut = btnOut;

            //Assign the btnRelease function to the button onRelease state.

            tl["btn"+(i)].onRelease = btnRelease;

            }

            }

             

            //xml

             

            <NAVBAR>

               <BUTTON LINK='http://www.google.com'><![CDATA[text <i>italic text</i> text]]></BUTTON>

               <BUTTON NAME='button 1' LINK='http://www.google.com' />

            </NAVBAR>

             

            Thanks for the quick response.

            • 3. Re: italic text from xml file to create dynamic menu
              kglad Adobe Community Professional & MVP

              again, use firstChild.nodeValue:

               


               

               

              myXML.onLoad = function(){

              //Set varible to store the XML childNodes

              //This allows you to get the number of buttons in the XML file.

              //You'll use this tell flash how many times to loop the for loop.

              var linkname:Array = this.firstChild.childNodes;

              //Set a for loop

              for(i=0;i<linkname.length;i++){

              //Push the button name into the names Array

              if (linkname[i].attributes.NAME) {

              names.push(linkname[i].attributes.NAME);

              }

              else {

              names.push(linkname[i].firstChild.nodeValue);

              }

              //Push the button link into the links Array

              links.push(linkname[i].attributes.LINK);

              //Attach the button Movie Clip from the libray give it an instance name and place it on the next highest level

              tl.attachMovie("button","btn"+i,tl.getNextHighestDepth());

              //Set the y position of the buttons

              tl["btn"+i]._y = yPosition;

              //Increace the varible yPosition 15 pixel each time the loop runs to place each button under each other

              yPosition = yPosition + 18;

               

              //set text to html text

              tl["btn"+(i)].blackTxt.Txt.html = true;

              tl["btn"+(i)].whiteTxt.Txt.html = true;

              //Place the button name from names Array into the blackTxt text box

              tl["btn"+(i)].blackTxt.Txt.htmlText = (names[i]);

              //Place the button name from names Array into the whiteTxt text box

              tl["btn"+(i)].whiteTxt.Txt.htmlText = (names[i]);

              //Assign the btnOver function to the button onRollOver state.

              tl["btn"+(i)].onRollOver = btnOver;

              //Assign the btnOut function to the button onRollOut state.

              tl["btn"+(i)].onRollOut = btnOut;

              //Assign the btnRelease function to the button onRelease state.

              tl["btn"+(i)].onRelease = btnRelease;

              }

              }

               

              //xml

               

               

              <NAVBAR>

                 <BUTTON LINK='http://www.google.com'><![CDATA[text <i>italic text</i> text]]></BUTTON>

                 <BUTTON NAME='button 1' LINK='http://www.google.com' />

              </NAVBAR>

               

              Thanks for the quick response.

              1 person found this helpful
              • 4. Re: italic text from xml file to create dynamic menu
                wwscoper Level 1

                Thanks Kglad. I tried this but it doesn't seem to be working correctly. Everything between the "<i>the text between these tags is removed</i>" is removed from the string.

                • 5. Re: italic text from xml file to create dynamic menu
                  kglad Adobe Community Professional & MVP

                  are you doing something that requires an embedded font and you're failing to embed italic font?

                  • 6. Re: italic text from xml file to create dynamic menu
                    wwscoper Level 1

                    Yes, I am embedding the font. I know I have the regular version of the font embedded. Is there any special trick to embedding two fonts for the same text box? I tried embedding the italic version too, but maybe I did something wrong.

                    1 person found this helpful
                    • 7. Re: italic text from xml file to create dynamic menu
                      kglad Adobe Community Professional & MVP

                      the easiest way to embed italic font is to create a textfield (offstage and/or not visible) and embed the font like normal and toggle the italic button.

                      1 person found this helpful
                      • 8. Re: italic text from xml file to create dynamic menu
                        wwscoper Level 1

                        Thanks Kglad! The menu is working now with regular and italic fonts.