This can be a tricky thing to get just right. I had to fight with this about 10 days ago and only though trying several combinations of names and parameters to the embed could I get it to work.
I read blog reports that had anecdotal advice that you had to include the fontStyle if you need bold or whatnot. Here is the incantation that worked for me:
[Embed(source="assets/HelveticaBold.ttf",
fontName="HelveticaBold",
fontWeight="bold",
unicodeRange='U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E')]
private static var HelveticaBold:Class;
I don't think unicodeRange
is strictly necessary but I didn't need the entire font and the above gives you the equivalent of "Basic Latin" in the IDE.
When I want to use the font I do so like this:
var titleFormat:TextFormat = new TextFormat();
titleFormat.font = "HelveticaBold";
titleFormat.bold = true;
titleFormat.color = 0x0;
titleFormat.size = 18;
var errorTitle:TextField = new TextField();
addChild(errorTitle);
errorTitle.embedFonts = true;
errorTitle.autoSize = TextFieldAutoSize.LEFT;
errorTitle.antiAliasType = AntiAliasType.ADVANCED;
errorTitle.x = 5;
errorTitle.y = 5;
errorTitle.defaultTextFormat = titleFormat;
I can't believe I missed the most important piece. The above didn't work until I forced the mxmlc compiler to use a custom font manager.
Add the following as a compiler option:
-managers=flash.fonts.AFEFontManager
There is an Adobe technote on troubleshooting fonts in Flex 3 that lists the available font managers. Try them until you find one that works.