I don’t think we are ever going to see a solution for embedding fonts in ActionScript that is easy to use. In AS3 we were introduced to the use of the [Embed] tag, allowing you to embed files both from the local system, and also from exported swf files. Extra options include the option to specify the unicode character ranges, to save on file size. The best solution, is to use runtime shared libraries or make use of getDefinitionByName() to extract them out of loaded swf, however what happens if you need a textual preloader to load the font swf, and you get the fatal “Unable to transcode Font” message when using the embed tag in the flex compiler?
Well, firstly this happens because there are three font transcoders in the Flex compiler, and they all prefer TrueType fonts, and all suck (in my humble opinion). So the solution is to use the old faithful Flash IDE to handle your PostScript related font issues.
To do this, create a TextField instance inside a symbol and give it an instance name like “textField”, make sure you select the “embded fonts” option and only include the number of characters you require. Next mark the symbol for export and remember the class name (you don’t need to create a corresponding .as file for this class, one will be generated for you, also it doesn’t matter if you have the “declare stage instances” option on or off, this will be handled by for you as well).
The next step is then to use the embed tag to import this symbol (quick tip use the # symbol after the .swf to access the class name quickly e.g. [Embed (source="embeddedFields.swf#FontField")] ) and then all you need to do is instantiate the class and use inline array notation to access the TextField instance and use it like a regular textfield, like (fontFieldInstance['textField'] as TextField).text = “ta da”;
Peezy

3 Responses to “Ah Yes, The Old “Fix Font Embedding Problems By Sneakily Embedding An IDE Created MovieClip With A TextField Instance” Solution”

  1. Sam Says:

    Hi Alex,

    It’s nice to see you have found yet another way of embedding fonts, do you have a simple working example of this?
    Thanks
    Sam (I hate fonts) Hassan.

  2. Chris Says:

    Interesting how separated by miles of country and years of time we end up working on the same problem. Dynamic font embedding will continue to be a pain for all of us.
    Having not touched flex yet I might have to look into your work more.

  3. Nish Says:

    I have used similar solution more than 2 years ago with a project.
    http://www.digitalprintexpress.co.uk

Leave a Reply