Flash CS4 <b> tag in with htmlText

戏子无情 提交于 2019-12-02 00:52:15

问题


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.


回答1:


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>."



回答2:


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.




回答3:


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.




回答4:


v = v.split('<b>').join('<FONT FACE="Arial Bold">');
v = v.split('</b>').join('</FONT>');
textfield.htmlText = v;

and use you font face



来源:https://stackoverflow.com/questions/2363903/flash-cs4-b-tag-in-with-htmltext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!