Table of Contents

TextFormat.font Property Flash 6

sets the font for specified characters read/write
theFormat.font

Description

The string font property specifies the name of the font in which characters should be displayed. For text fields with font-embedding disabled, font should exactly match the name of a font on the playback system. For example, on Windows, the following code sets theField_txt's font to Arial:

this.createTextField("theField_txt", 1, 0, 0, 200, 20);
theField_txt.embedFonts = false;
theField_txt.text = "This text is in Arial."
format = new TextFormat();
format.font = "Arial";
theField_txt.setTextFormat(format);

For a list fonts installed on the playback system, use TextField.getFontList( ). When embedded fonts are enabled for a text field, the font property must match one of the following:

For more information on embedding fonts with a movie see TextField.embedFonts.

To set the font for an entire text field, invoke TextField.setTextFormat( ) without specifying any index arguments:

// Make the whole field Arial
theField_txt.setTextFormat(format);

To set the font for a single character, apply the format with a single index argument:

theField_txt.setTextFormat(0, format); // Make the first character Arial

To set the font for a range of characters, apply the format with start and end index arguments:

theField_txt.setTextFormat(0, 4, format);  // Make the word "This" Arial

The default font value (as contained in the TextFormat object returned by TextField.getTextFormat( )) for a text field that contains text is "Times New Roman". For a text field without any text, the font value is null. For a completely new TextFormat object, it is also null, indicating that font will not be set when the format is applied to a text field:

trace(anyUnformattedField_txt.getTextFormat().font); // Displays: "Times New Roman"
var format = new TextFormat();
trace(format.font);                                  // Displays: "null"

For text fields with font-embedding disabled, the font property can contain a comma-separated list of fonts. Flash will render the text field with the first available font in the list. For instance, "Arial,Helvetica,_sans" (no spaces between font names!) causes the Player to search for the font Arial, then Helvetica (if Arial is not found), then _sans (if neither Arial nor Helvetica is found). This is an undocumented feature of the Flash Player; however, it mirrors the behavior of HTML text font-rendering in browsers.

See Also

TextField.embedFonts, TextField.getFontList( )


Table of Contents