Flash CS4 <b> tag in with htmlText

Wow, this one is really weird.

I have the following setup:

Two textfields on the stage with Arial normal and Arial bold, both embedded. I then have another textfield which I am setting like so:

tb.htmlText = "Test <b>Test</b>";

For some reason, the bold text is not displaying as bold, but as regular weight. I have tried embedding the fonts in the library, using the [Embed] meta tag and even resorted to using CSS to force the fontFamily. Weirdly, I can use Font.enumurateFonts and see both fonts are embedded, but the textfield refused to use the bold version inside the < b > tags.

I've been told this is a problem with Flash CS4 on a mac and that it will work on PC. I refuse to believe this is the case, however. Surely Adobe would have fixed this by now?

Any help would be appreciated.


You've gotta have the 'bold' font in the Font list ( embbed in the same or in other textfield ) :

var fonts:Array =  ( Font.enumerateFonts() );
for each( var fo in fonts ){
   trace ( fo.fontName ,":", fo.fontStyle )
}

I think that if you had the fontstyle returning as bold it probably should work with no prob. Here's a solution:

var css:StyleSheet = new StyleSheet()
css.setStyle( "bold" , { fontFamily:"Myriad Pro Bold" } ) // you can catch the fontname in the list that was printed by the code above...
txtfield.styleSheet = css;
txtfield.htmlText = "regular or<bold>bold font</bold>."

From Adobe:

The bold b tag renders text as bold. If you use embedded fonts, a boldface font must be available for the font or no text appears. If you use fonts that you expect to reside on the local system of your users, their system may approximate a boldface font if none exists, or it may substitute the normal font face instead of boldface.

Try it with an embedded font that has a boldface. The b tag is supported.


If you have a dynamic textfield with font family, let's say, "Abc" and you have embedded both, Abc's Regular as well as Abc's Bold for export (they will be listed in your library), you still need to "force" Flash to also export the bold for runtime.

If you have only textfields that use the embedded Abc Regular and you set htmlText of that textfield with and it is displayed as regular text, Flash most likely skipped embedding Abc Bold to your swf for runtime, because it did not see it used on any textfield.

You can force flash to also include the bold for runtime by placing and empty textfield with the embedded Abc Bold somewhere off stage.

Using queryt's code, font listing should then include the embedded bold as well as showing the correctly in your textfield.

链接地址: http://www.djcxy.com/p/2940.html

上一篇: 加载外部数据时Flash CS4 IDE内部缓存

下一篇: 使用htmlText Flash CS4 <b>标记