Recipe 8.19 Setting a Text Field s Font

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:

myTextField.setTextFormat(myTextFormat);

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



ActionScript Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2005
Pages: 425

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net