Embedding fonts in AS3

Hi,

In this post i ll explain how to embed fonts in as3.. Fonts should be embedded to dynamic text boxes because if dynamic text boxes are masked, they wont render the text in runtime unless font is embedded to it.

First you should import a font to your library..

step1 : Right click on the library panel area where the items in library are displayed.

Step2 : Select NEW FONT…

step3 : Choose whichever font you want and specify its size and its bold, italic properties.
Note : Dont forget to check the “Bitmap Text” checkbox.

Step4 : Now right click on the Font 1 in your library, and choose Linkage.

Step5 : Check the “Export for ActionScript” checkbox.

Step6 : Change the class name to whatever you want, here for example am changing it to f1.

Now you have imported a font successfully to ur library, now lets see how to embed it to ur text box.

Step7 : Create a dynamic text box and assign its Instance Name as “test”

Step8 : Create a new text format and assign the imported font to it. Below is the code for it.

var format:TextFormat = new TextFormat();
format.font = new f1().fontName;
format.size = 15;
format.letterSpacing = 0.8;

Step9 : Then assign this font to your dynamic text box.. Below is the code for it.

test.embedFonts = true;
test.antiAliasType = AntiAliasType.ADVANCED;
test.autoSize = TextFieldAutoSize.NONE;
test.selectable = false;
test.defaultTextFormat = format;

Compile and check.. :)

Hope this helps.. If u have any further doubts, leave a comment.. :)