Saturday, March 5, 2011

Embedding Fonts

If you noobs are wondering how to embed fonts into your SWF using code, then below is an example on how to achieve it.

Here, I have a FontManager class that contains the fonts I want to include in my SWF.

package {
  public class FontManager {
   
 [Embed(systemFont='Arial', fontName="Arial", mimeType="application/x-font-truetype")]
 public static const FONT_ARIAL:String;

 [Embed(systemFont='Verdana',fontName="Verdana",mimeType="application/x-font-truetype")]
 public static const FONT_VERDANA:String;

 [Embed(source='/fonts/NEWB.TTF', fontName="Newb", mimeType="application/x-font-truetype")]
 public static const FONT_NEWB:String; 

 [Embed(source="C:\WINDOWS\Fonts\SEXY_TIME.ttf", fontName="SexyTime", mimeType="application/x-font-truetype")]
 public static const FONT_SEXY_TIME:String;

 }
}
package {
  public class EmbedFontExample {
    public function EmbedFontExample() : void {
      var font1:String = FontManager.FONT_SEXY_TIME;
    }
  }
}

There you have it.  Now you know how to embed fonts.

Related Links:
Embed Images/JPG/PNG/SWF
Error Transcoding

No comments:

Post a Comment