I want to go through the text in a TextField and switch each and only those characters which cannot be represented in the font of the TextField over to a different font (non-standard characters such as a not equal sign ≠ or fourth power ⁴ are not available in every font.) I used this code to determine which characters cannot be represented.
var fontName:String = textField.getTextFormat().font;
var fontArray:Array = Font.enumerateFonts(true);
var textFont:Font;
for each (var font:Font in fontArray) {
if (fontName == font.fontName) {
textFont = font;
}
}
trace(fontName == textFont.fontName); // true
var text:String = textField.text;
var char:String;
for (var index:int = 0; index < text.length; index++) {
char = text.charAt(index);
if (!textFont.hasGlyphs(char)) {
trace("no glyph: " + char);
}
}
This code traces every single character in the TextField. hasGlyphs returns false for every single character, most of which display perfectly clearly in the TextField. Apparently, hasGlyphs simply does not work. Am I missing something here?