1 CommentMay 26 | 2009
Simple class to include dynamic fonts in your flash movie. You can either compile this from your fav AS editor or apply it to an FLA as the document class.
To access the fonts, all you will need to is load in the generated swf into your project and use the fontName value you specify in the class to apply the appropriate font.
It’s also good practice to limit the unicode range to characters you need. Adobe provides a good reference, flash-unicode-table.xml, which you can find inside the Flex SDK 2/frameworks folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | package { import flash.display.MovieClip; import flash.text.Font; public class Fonts extends MovieClip { [Embed(source='C:/WINNT/fonts/DiCnBd.ttf', fontName='_dinBold', unicodeRange='U+0021-U+007A,U+00BB,U+00A9,U+2122,U+00AE')] public static var _dinBold:Class; Font.registerFont(_dinBold); trace("_dinBold LOADED"); [Embed(source='C:/WINNT/fonts/arial.ttf',fontName='_Arial', unicodeRange='U+0021-U+007A,U+00BB,U+00A9,U+2122,U+00AE')] public static var _Arial:Class; Font.registerFont(_Arial); trace("_Arial LOADED"); [Embed(source='C:/WINNT/fonts/arialbd.ttf', fontWeight= "bold",fontName='_ArialBold', unicodeRange='U+0021-U+007A,U+00BB,U+00A9,U+2122,U+00AE')] public static var _ArialBold:Class; Font.registerFont(_ArialBold); trace("_ArialBold LOADED"); } } |












Additional Info:
If you are trying to embed a PFM font you might get the following compiler error: “Error: exception during transcoding: Font for alias … was not found at:”
This happens as PFM is a supporting font file and not the actual font file itself. PFB needs to be used instead as that contains the actual data.
[Embed(source='C:/windows/fonts/HLLC___.PFB',mimeType="application/x-font-truetype", fontName='hnLightCon', unicodeRange='U+0021-U+007A,U+00BB,U+00A9,U+2122,U+00AE')]
public static var _hnLightCon:Class;
Font.registerFont(_hnLightCon);
trace(”Fonts:_hnLightCon LOADED”);
You must also provide the mimeType or else the compiler generates the following error: “Error: ‘*.PFB’ does not have a recognized extension, and a mimeType was not provided”