TextField.embedFonts Property | Flash 6 |
render text using fonts exported with the movie | read/write |
The Boolean embedFonts property specifies whether a field's text is rendered using device fonts on the user's system (false) or fonts embedded in the .swf file (true). When embedFonts is false, text appears without antialiasing and missing fonts are replaced by the system's default font (usually some variation of Times New Roman). When embedFonts is true and the field's fonts are exported with the .swf file, text appears antialiased. When embedFonts is true but one or more of the field's fonts is missing from the .swf file, text in the missing fonts does not appear at all. Embedding a complete Roman font typically adds 20-30 KB to a movie (Asian fonts can be much larger). Using embedded fonts with sizes smaller than 10-point is not recommended, because antialiased text becomes unreadable below 10-point in most fonts.
|
To export (i.e., to embed) a font with a .swf file, we must do one of the following:
Create a new font symbol in the movie's Library.
Manually add a dummy text field at authoring time and set its Character options in the Property inspector.
The font symbol approach always exports an entire font, while the text field approach allows us to export only part of a font, reducing file size. To export a subset of a font with a font symbol, we must use font-making software such as Macromedia Fontographer to create a custom font as a subset of the original font.
To export Arial Bold using a font symbol:
Select Window Library.
From the pop-up Options menu in the upper-right corner of the panel, select New Font. The Font Symbol Properties dialog box appears.
Under Font, select Arial.
Under Style, select Bold.
Under Name, type ArialBold (this is a cosmetic name, used in the Library only).
In the Library, select the ArialBold font symbol.
From the pop-up Options menu, select Linkage.
In the Symbol Linkage Properties dialog box, under Linkage, select Export For ActionScript.
In the Identifier box, type ArialBold. This name will be used as the value of a TextFormat object's font property.
To export any font using a dummy text field:
Select the Text tool.
Draw a rectangle on stage.
In the Property inspector, choose the desired font. The font's actual name will be used as the value of a TextFormat object's font property.
In the Property inspector, click the Character button and choose the character outlines to export.
Every variation of a font style must be embedded individually. If we use Courier New in bold, italic, and bold italic in a text field, then we must embed all three font variations or the text will not display correctly. Underline is not considered a font variation, nor is font size or color.
|
To specify the font for a text field, use a TextFormat object and the TextField.setTextFormat( ) and TextField.setNewTextFormat( ) methods. To retrieve a list of fonts available on the user's system, use TextField.getFontList( ).
On operating systems that support Unicode (e.g., Windows XP and Mac OS X), when embedFonts is false and a character is needed that is not available in the specified font, Flash will automatically search the system for a font that can represent the character. If a suitable font is found, it will be used until the next missing character is encountered, at which point Flash will again search for a suitable font.
Theoretically, to apply the same embedFonts value to all text fields in a movie, we would use this syntax:
TextField.prototype.embedFonts = true;
However, in Flash 6, built-in properties set on TextField.prototype are not inherited by text field instances.
Assuming the Verdana font is exported, the following code causes theField_txt to be rendered in antialiased Verdana:
// Make the text field this.createTextField("theField_txt", 1, 0, 0, 150, 40); // Tell the field to use embedded fonts theField_txt.embedFonts = true; // Assign some text to the field theField_txt.text = "How are you?" // Create and apply a text format with a font of Verdana defaultFormat = new TextFormat(); defaultFormat.font = "Verdana"; theField_txt.setTextFormat(defaultFormat);
TextField.getFontList( ), TextField.setNewTextFormat( ), TextField.setTextFormat( ), TextFormat.font