
TextField.getNewTextFormat() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
839
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 ...