Recipe 8.19 Setting a Text Field's Font

8.19.1 Problem

You want to use ActionScript to change the font used for some displayed text.

8.19.2 Solution

Set the font property of a TextFormat object and apply the formatting to the text field.

8.19.3 Discussion

You can programmatically specify the font that is used to display text using the font property of a TextFormat object. You can assign to this property the string name of the font (or fonts) that should be used:

myTextFormat.font = "Arial";

The font specified must be available on the computer on which the movie is running. Because some computers may not have the preferred font installed, you can specify multiple font names separated by commas, as follows:

myTextFormat.font = "Arial, Verdana, Helvetica";

The first font is used unless it cannot be found, in which case the Player attempts to use the next font in the list.

Apply the font change to a text field, as follows:


If none of the specified fonts are found, the default system font is used.

8.19.4 See Also

Recipe 8.16, Recipe 8.18, and Recipe 8.20

    Part I: Local Recipes
    Part II: Remote Recipes