Embedding partial fonts in Adobe Flash CS3 for use in ActionScript 3 (AS3)

Long post title but its to help me remember it once and for all. I’ve lost too much time to font embedding in AS3 only to find that I’ve tested it on a machines with the fonts installed and the embedding isn’t actually working. I’m not going to go into super detail about it, I’m assuming that you’ve got it 99% of the way and are struggling (and swearing) because it doesn’t stick.

First, some don’ts:

  • Don’t use the library. The library is for full font embedding – not partial – and can increase your file by 20 to 30 KB (or more if you’ve got a Unicode font!)
  • Don’t use [Embed(source="C:WINDOWSFontssomefont.ttf", fontFamily="foo")]. I don’t even know if that works but I assume that if it did it would embed the full font which would lead to the previous problem.

Now the process:

  1. Draw a text field on the canvas but off the stage and set it to Dynamic Text
  2. Set the text field’s font to the font that you want to embed
    • You may or may not have to set the size to what you want to use, haven’t tested that yet
  3. Press the embed button in the Properties palette  and select your characters.
    • Don’t forget to include any and all punctuation characters that you’re using.
    • Consider maintenance – is it worth 2KB to exclude a couple of letters you’re not using now only to forget in a couple of months how to add them? Maybe you should just add all of A-Z.
    • If you type your own in don’t forget to include the space character!
  4. In your code, reference the font using the exact same name that’s in the dynamic text field’s font menu
    • In fact, copy it out of the menu. I once had a font with two spaces side-by-side in the name. Several hours were wasted on that.
    • var NavItemTextFormat_MouseOff:TextFormat = new TextFormat("Aviano Sans Bold", 12,0x000000,true,false,false,null,null,TextFormatAlign.RIGHT);
  5. Last and most important, after you call setTextFormat() on your TextField, you also have to set the embedFonts to true
    NavItem.setTextFormat(NavItemTextFormat_MouseOff);
    NavItem.embedFonts = true;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.