home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

Book HomeActionScript: The Definitive GuideSearch this book

18.5. HTML Support

The Character panel lets us set a text field's font size, font face, and font style, but it sets the attributes of the entire text field only. To set styles on a character-by-character basis and to add hypertext links, use HTML (which was added as a text field feature in Flash 5).

Though HTML can be used with both dynamic text fields and user-input text fields, we normally use HTML text fields for display purposes only. To add HTML support to a text field, select the HTML option in the Text Options panel.

The set of HTML tags supported by text fields is limited to: <B>, <I>, <U>, <FONT>, <P>, <BR>, and <A>.

18.5.4. <FONT> (Font Control)

The <FONT> tag supports the following three attributes:


The FACE attribute specifies the name of the font to use. Note that a list of multiple font faces is not supported in Flash as it is in HTML. Flash attempts to render only the first font listed in the FACE attribute. For example, in the code <FONT FACE="Arial, Helvetica">my text</FONT>, Flash will not render "my text" in Helvetica if Arial is missing. Instead, text will be rendered in the default font.


The SIZE attribute specifies the size of the tagged text as a fixed point size (such as <FONT SIZE="18">) or as a relative size. Relative point sizes are preceded by a + or - sign and are specified relative to the text size in the Character panel. For example, if the point size is 14 in the Character panel, then <FONT SIZE="-2"> displays the tagged text at 12 point.


The COLOR attribute specifies the color of the tagged text, as a hexadecimal number, preceded by the pound sign (#). For example: <FONT COLOR="#FF0000">this is red text</FONT>. Specify the hexadecimal number as an RGB series of three two-digit numbers from 00 to FF. Note that Flash's implementation of the COLOR attribute is more strict than HTML's -- the pound sign (#) is required, and color names such as "green" and "blue" cannot be used as COLOR values.

Here are some <FONT> examples:

<FONT FACE="Arial">this is Arial</FONT>
<FONT FACE="Arial" SIZE="12">this is 12pt Arial</FONT>
<FONT FACE="Lucida Console" SIZE="+4" COLOR="#FF0000">this is red, 
+4pt Lucida Console</FONT>

See Section 18.5.11, "Using HTML as Output" later in this chapter for more important details on fonts in Flash.

18.5.7. < A> (Anchor or Hypertext Link)

The <A> tag creates a hypertext link. When the user clicks text tagged with <A>, the document specified in the HREF attribute of the tag loads into the browser. If the Player is running in standalone mode, the default web browser on the system is launched and the document is loaded into that browser.

The generic syntax of the <A> tag is:

<A HREF="documentToLoad.html">linked text</A>

For example, to link to a good video game, we could use:

<A HREF="http://www.quake3arena.com/">nice game</A>

As with HTML, the URL can be absolute or relative to the current page. Normally, links followed via an anchor tag cause the current movie to be replaced with the document specified in the HREF of the anchor tag. However, an anchor tag may also cause a secondary browser window to launch. Using the TARGET attribute, we can specify the name of a window into which to load the linked document, as follows:

<A HREF="documentName" TARGET="windowName">linked text</A>

If a window named windowName does not already exist, the browser launches a new window and assigns it the name windowName. To launch each document in its own, anonymous window, we can use the _blank keyword, as in:

<A HREF="mypage.html" TARGET="_blank">linked text</A>

Note that when we launch windows through the TARGET attribute, we have no control over the size or toolbar arrangement of the new window. To launch specifically sized windows from a link, we must use JavaScript. Techniques for launching customized secondary windows with JavaScript are described at:


For more information on communicating with JavaScript from ActionScript, see the global functions fscommand( ) and getURL( ) in Part III, "Language Reference", and Section 18.5.13, "Executing JavaScript from HTML Links" later in this chapter.

The TARGET attribute can also be used to load documents into frames, as in:

<A HREF="documentName" TARGET="frameName">linked text</A>

Flash anchor tags do not always behave exactly like HTML anchor tags. We cannot, for example, use the NAME attribute of the anchor tag in Flash, so internal links within a body of text are not possible. Furthermore, Flash links are not underlined or highlighted in any way. Link underlines and colors must be inserted manually with the <U> and <FONT> tags described earlier.

18.5.11. Using HTML as Output

HTML text entered manually into a text field using the Text tool will not be rendered as HTML. To display HTML-formatted text on screen, we must assign HTML text to a dynamic text field via ActionScript. For example:

myTextField = "<P><B>Error!</B> You <I>must</I> supply an email address!</P>";

Embedding a font for an HTML text field embeds only a single style of a single font. For example, a text field set to bold Arial in the Character panel will only support characters of the Arial bold typeface. If we use HTML to assign a different style of Arial (such as italic) or a different typeface altogether (such as Garamond), the tagged text will be invisible unless the appropriate fonts are embedded with the movie!

Suppose, for example, that we create a text field called output. In the Character panel for our output text field we select Arial set to Italic. In the Text Options panel, we embed the entire Arial italic font. Then we set output to display HTML. Finally, we assign the following value to our text field:

output = '<P><I>My</I>, what <B>lovely</B>'
         + '<FONT SIZE="24">eyes</FONT> you have!</P>';

When the movie plays, the following text will appear in the text field:


Everything else we assigned to output is missing! Only the italic text in the HTML can be rendered. The rest of the text requires other variations of the Arial font that we didn't embed -- "what", "eyes", and "you have" are all nonitalic, and "lovely" is bold.

For every font face and variation we use in an HTML text field, we must embed the appropriate font. We have two means of doing so:

  • Make a dummy text field, hidden from view, with the desired font selected in the Character panel and embedded in the Text Options panel.

  • Add a new font symbol to the movie's Library and export the font with the movie.

Here are the steps for embedding Arial bold in a movie for use with a text field:

  1. Select Window Library.

  2. Select Options New Font. The Font Symbol Properties dialog box appears.

  3. Under Font, select Arial.

  4. Under Style, select Bold.

  5. Under Name, type ArialBold (this is a cosmetic name, used only in the Library).

  6. In the Library, select the ArialBold font symbol.

  7. Select Options Linkage.

  8. In the Symbol Linkage Properties dialog box, select Export This Symbol.

  9. In the Identifier box, type ArialBold. For our purposes, the name we type here doesn't matter. Exported symbol identifiers are used only for shared libraries.

Note that every variation of a font style must be embedded individually. If we use Arial bold, Arial italic, and Arial bold italic in a text field, then we must embed all three font variations. Underline is not considered a font variation, nor is font size or color.

If, however, we do not enable any of the Embed Fonts options in the Text Options panel, then Flash relies entirely on the user's system for fonts, in which case normal, bold, and italic text will be rendered only if users have the appropriate font variant installed on their systems.

To ensure that text will display consistently across all platforms and user systems, you should embed all the fonts required for your text field.

Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.