TextField.embedFonts Property

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
TextField.embedFonts Property Flash 6

render text using fonts exported with the movie read/write
theField.embedFonts

Description

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.

The contents of a text field that is rotated or masked with an author-time mask layer will not show up on screen unless its font is embedded. However, as of Flash Player 6.0.40.0, MovieClip.setMask( ) can be used to apply a rectangular mask to a text field at runtime without embedded fonts. See MovieClip.setMask( ) for details.

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:

  1. Select Window figs/u2192.gif Library.

  2. From the pop-up Options menu in the upper-right corner of the panel, select 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 in the Library only).

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

  7. From the pop-up Options menu, select Linkage.

  8. In the Symbol Linkage Properties dialog box, under Linkage, select Export For ActionScript.

  9. 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:

  1. Select the Text tool.

  2. Draw a rectangle on stage.

  3. 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.

  4. 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.

Setting embedFonts to true does not cause any fonts to download with the movie; it merely indicates that theField should be rendered with exported fonts if they are available. The embedFonts property must be set separately for each text field that uses a particular font, even if multiple text fields use the same font. However, file size is not affected when multiple text fields embed the same font only one copy of the font is downloaded with the movie.

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.

Bugs

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.

Example

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);

See Also

TextField.getFontList( ), TextField.setNewTextFormat( ), TextField.setTextFormat( ), TextFormat.font



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

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