Table of Contents

TextField.getFontList( ) Class Method Flash 6

returns an array of fonts on the user's system
TextField.getFontList()

Returns

An array of font names as strings.

Description

The getFontList( ) class-level method tells us what fonts are installed on the system playing a Flash movie. We can use any of the fonts listed as a device font for a text field, provided that the field has embedFonts set to false. To assign a font to a text field, use the font property of a TextFormat object and the TextField.setTextFormat( ) method.

Only families of fonts are listed by getFontList( ), as would appear in the text field Property inspector's font selector. Variations, such as bold or italic versions of a font, are not listed. To use a bold or italic variation of a font, set the bold or italic property of a TextFormat object, in addition to the font property, before applying it using TextField.setTextFormat( ) or TextField.setNewTextFormat( ).

Typical uses for getFontList( ) include selecting a fallback font automatically (see the following Example) and letting the user select a font.

Usage

Note that getFontList( ) is called directly as a method of the TextField class, not through an instance of the class:

someTextField_txt.getFontList();  // Wrong way...won't work.
TextField.getFontList()           // Right way.

Bugs

In Flash 6, the getFontList( ) method does not return names of fonts exported with a movie.

Example

The function assignFont( ) takes an array of font names and returns the first one that is found on the user's system. If none is found, assignFont( ) returns null:

this.createTextField("theField_txt", 1, 0, 0, 150, 40);
theField_txt.text = "Flash is fun!";
defaultFormat = new TextFormat();
defaultFormat.font = assignFont(["ZapfChancery", "Verdana", "Arial", "_sans"]);
theField_txt.setTextFormat(defaultFormat);
function assignFont (fontList) {
  var systemFonts = TextField.getFontList();
  for (var i = 0; i < fontList.length; i++) {
    for (var j = 0; j < systemFonts.length; j++) {
      if (fontList[i] =  = systemFonts[j]) {
         return fontList[i];
      }
    }
  }
  return null;
}

See Also

TextField.embedFonts, TextField.setTextFormat( ), TextFormat.bold, TextFormat.font, TextFormat.italic, the TextFormat class


Table of Contents