How to Get Flash AS2 to Display Italicized HTML Text
Wacky Flash quick tip #127:
A co-worker of mine recently asked me how to get italics to appear in a Flash html Text Field. Use the i tag I told him but he said he tried that and the text disappeared altogether. Assuming he was deranged I quickly opened a new Flash document and attempted to demonstrate what I was talking about.
I created a dynamic text field, marked it as html, embedded my font, gave it an instance name, wrote a little AS to populate it and hit CTRL-ENTER. To my surprise, there was no text on the stage. After retracing my steps to make sure I didn’t miss anything I tried again to make sure. Nope, still not working. It ended up taking me about 20 minutes to figure out.
Here’s the trick:
You have to place a dynamic text field on the stage for each style of the font you want to use. For example, the string I’m using to populate the field is “hello there”, so I had to place one dynamic text field with the italic font style embedded and another embedded with no style. Once that was done it worked perfectly.
I thought the whole process was pretty bizarre which is why I’m posting it. If it doesn’t benefit anyone else at least it’ll be here for my own personal reference
.
If you’re interested, here’s a .fla to demonstrate.
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.



This one hit me awhile back and seems to be one of the lesser known nuances of dynamic text with little documentation about it. One thing to consider with using formatted text via HTML (especially with CMS driven sites) is that allowing for bold, italic, or bold-italic formatting has an impact on file size because you have to embed characters for each style. Unfortunately, the TextField doesn’t degrade to normal text if no styled text is embedded, so you really have to know ahead of time what formatting you want to allow and prepare the text to support it.
heh, that’s a workaround
you can do it another, cleaner way
include font in a library
but you have to include every font style as separate font
you can find example and blogpost at
Font Embedding on Cyberspace Nova
TextField.StyleSheet can help you.
this let your textfield support the css property ‘font-style’ as ‘italic’.
Thanks for the alternate solutions. I’ll definitely try them out.
I am not sure if the style sheet would work or not. It is an issue of the font not being embedded properly for a dynamic text field. Flash treats the Normal, Bold, and Italicized text in an htmlText field as different font sets. Glenn’s way will definitely work for this. I used to do exactly the same thing, I would have every letter/number/symbol for a font set in a dynamic text field on the root, with one Bold, one Italicized, and one Normal.
Now I use something different with the shared font libraries. I have to set it up in the font library file that we load in externally and then never have to worry about it again, since the fonts are shared library swf’s outside of my main flash piece.
@Jeff: Shared libraries, eh? Any chance for a post on thewarp.org about that?
I have an issue that’s a bit different. If I make an SWF file with dynamic text in it and view it in my browser, it looks fine and the dynamic text is displayed.
If I have a Flash application running on a website and I load the same SWF, all is fine except the dynamic text: it is not displayed!
Any suggestions?
Hi Gratis,
Sounds like you’re forgetting to embed your font. When you use dynamic text fields you have to embed the font characters you’ll be using. Use the Embed button in the text field’s properties panel to do so.
rG
CAN YOU ATTACK A .FLA FILE FOR 2004 MX TOO/
I figured this might help someone. First part is obvious – create a font symbol in the library for each font you wish to use and in every variant (bold, italic, etc). Name them appropriately and export to use with actionscript (using different linkage names, probably same as their names in the library).
Everything works cool unless you use CSS or tags inside your text. The formatting for the entire textfield reverts to what it was set in your flash workspace.
In order for your nice exported font styles to be usable, you need to input their linkage names inside tags or CSS rules. For example:
This is oblique.
And that worked for me
Cheers.
wao, i’m surprised by the tricks
and my problems get solve
thank’s alot
this is what i’m looking for
thanks, let me try this out and see