问题
I've been trying to figure out for a while now. I usually manage to make my textFields work properly, but this is just driving me nuts.
I have this TextField that I inject HTML formatted text (contained in a XML file). For some reason, almost all my tags are ignored (<b>
,<i>
,<u>
,<ul>
and <li>
). I can only get it to render <br />
tags properly. I could use a StyleSheet, but I don't think it would make my lists work...
Here's how things are set up:
Text I inject:
<text>
<![CDATA[<b>Some bold text </b>and some normal text <br/><u>This text is underlined</u> normal text to compare<br/><i/>This text is italic</i>]]>
</text>
How my TextField is set:
// When my Class' setup method is called, I set those properties
_tf = _transcript.getTextFormat();
_tf.font = "Verdana";
_tf.size = 12;
_transcript.embedFonts = true;
_transcript.multiline = true;
_transcript.autoSize = TextFieldAutoSize.LEFT;
_transcript.wordWrap = true;
// In an function, later on
_transcript.htmlText = transcript; // transcript is a parameter. Basically, the XML I wrote above
_transcript.setTextFormat(_tf);
I DO have Verdana embed (as well as the variants). I made sure by generating a size report and tracing Font.enumerateFonts(). If I output the textField's htmlText after having set it up, I get this:
<P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="12" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">Some bold text and some normal text </FONT></P><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="12" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">This text is underlined normal text to compare</FONT></P><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="12" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">This text is italic</FONT></P>
I'm really out of ideas on why nothing's working, if anyone had any idea, I'd really appreciate it!!
Thank you
Edit: So I decided to test having no CDATA in my XML, and adding the <b>
tag in my AS3 code. Didn't work either. I don't get how I can have my fonts correctly embed, but Flash refusing to use them.
回答1:
Ok to get this to work, I have used the following syntax:
<mx:Text>
<mx:htmlText>
<![CDATA[<b>Some bold text </b>and some normal text <br/><u>This text is underlined</u> normal text to compare<br/><i/>This text is italic</i>]]>
</mx:htmlText>
</mx:Text>
I didnt try including any of the extra script you have in your question, but it seems to handle the html tags ok like this.
Also here is the livedocs reference I used to check my syntax...
http://livedocs.adobe.com/flex/3/html/help.html?content=textcontrols_04.html
Looking back at your question I've just realised that you probably aren't using Flex, ok so this is Flex specific, sorry.
来源:https://stackoverflow.com/questions/9502711/flash-is-ignoring-my-most-of-my-tags-in-a-html-textfield