actionscript-3formatundefinedtextfieldtextformat

as3 dynamically loaded font undefined fontname


I have a font I want to apply to a TextField, but before I could do that, it threw an undefined error. Here is my code:

var tFormat:TextFormat = new TextFormat();
trace(NumberFont);

which traces [class NumberFont] without problems, but I understand that I need a String, not a class to set the TextField font.

When I try to get the name: trace(NumberFont.fontName);

it gives a compiler error

1119: Access of possibly undefined property fontName through a reference with static type Class.

The code seems basic, but I am totally unfamiliar with TextFormat. What am I doing wrong?


Solution

  • You should instantiate the font and access the fontName instance property:

    var font:NumberFont = new NumberFont();
    var tFormat:TextFormat = new TextFormat(font.fontName);