italic text from xml file to create dynamic menu
Copy link to clipboard
Copied
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);
//Place the button name from names Array into the whiteTxt text box
tl["btn"+(i)].whiteTxt.Txt.htmlText = (names);
//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.
Copy link to clipboard
Copied
use the firstChild.nodeValue to assign names
Copy link to clipboard
Copied
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.attributes.NAME) {
names.push(linkname.attributes.NAME);
}
else {
names.push(linkname);
}
//Push the button link into the links Array
links.push(linkname.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);
//Place the button name from names Array into the whiteTxt text box
tl["btn"+(i)].whiteTxt.Txt.htmlText = (names);
//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.
Copy link to clipboard
Copied
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.attributes.NAME) {
names.push(linkname.attributes.NAME);
}
else {
names.push(linkname.firstChild.nodeValue);
}
//Push the button link into the links Array
links.push(linkname.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);
//Place the button name from names Array into the whiteTxt text box
tl["btn"+(i)].whiteTxt.Txt.htmlText = (names);
//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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
are you doing something that requires an embedded font and you're failing to embed italic font?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks Kglad! The menu is working now with regular and italic fonts.
Copy link to clipboard
Copied
you're welcome.

