Update. As pointed out by  Lupo, the [Embed] metadata tag can be used manually instead of taking this over-complicated route. I wager most of the internet knows this already, but I thought I’d update this post to avoid putting anyone on the wrong track.As posted by Lupo:�

[Embed(mimeType="application/x-font", source="terminator_real_nfi.ttf",fontName="Terminator")]
private var terminatorFontClass:Class;

I was hacking around with Flex Builder today and stumbled on a fairly easy way to handle font embedding for Actionscript projects without having to resort to Flash CS3 or venturing into the murky territory of using Flex classes in Actionscript projects. I only tested it with Flex Builder, but it’s all doable through the command line compiler as well. I will be creating a class that handles the nitty gritty on the Actionscript project side of things, but for more enterprising souls, I’ll describe the method I found.

  1. Create a CSS file with an @font-face entry for the font that you want to embed.
    /* CSS file */
        fontFamily: "Air Millhouse  Italic";
        fontWeight: normal;
        fontStyle: normal;
        src: local("Air Millhouse  Italic");
  2. Compile the CSS file using the following command-line syntax
    mxmlc -keep-generated-actionscript=true someFile.css
  3. Find the main class for your css swf (in my case someFile-generated.as)
  4. Locate the @Embed tag created for your font and copy down the class name and the font name. You can get the class name from the member name – they are the same except for the leading underscore.
    [Embed(mimeType='application/x-font', _pathsep='true', systemFont='Air Millhouse  Italic',
    _file='C:/Documents and Settings/HP_Administrator/My Documents/Flex Builder 3/fontTest_part1/src/fontEmbed.css',
    fontName='Air Millhouse  Italic', _line='8')]
    private static var _embed__font_Air_Millhouse__Italic_medium_normal_1778166867:Class;
  5. Load the css swf from your Actionscript project.
  6. This part is a little hacky. Maybe someone can fill me in on which event I need here. So far all I’ve been able to do to get this to work is to listen for Event.COMPLETE from the loader, and then on an Event.ENTER_FRAME check for one of the font definitions until it’s present.
  7. Grab a reference to the font using getDefinition() or getDefinitionByName() using the class name you got from the Embed (remember to remove the leading underscore)
  8. Call Font.registerFont() on the class you just grabbed
  9. The font is now available for use in your project.

The class name accorded to the font seems to be consistent no matter how many times I recompile the swf, so I wouldn’t expect it to change. It’s not especially pretty as solutions go, but it works, and it can be configured at runtime without too much trouble. Once I have some more free time I’ll try to dig a bit deeper into the CSS swf and see if this can be done more easily without going through Flex classes.