In this tutorial I will teach you how to embed a custom font. Embedding fonts is good practice in case if the person viewing your flash application or website does not have the font installed on their computer.

In your .fla file go to the library menu and select New Font

The library menu

A font properties menu will show up. Here you can edit the font name and the font. As you can see I have named font to be myFont Plain. This is because the font that Iam embedding is not bold nor italic. You can name it whatever you want but be descriptive to avoid confusion. The Font is named myFont. This is your main name for the font. Below are some checkboxes which help identify the style of the Font. If I style text with myFont, because I left the checkboxes blank the system will use myFont Plain. If I had created another font which was myFont, had its name as myFont Bold and then selected the bold style, I would have a Bold style for myFont. Now when I use myFont, I can use a bold tag around it and the myFont Bold will get shown.

After adding the new font you should be able to see it in your library. Right click on it and select Linkage. In the Linkage properties window check the box that says Export for ActionScript. You can name the class anything you want but make sure you don’t change the Base Class name.

Now go into your .as file. You will need to import the following classes to make this work.

import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.AntiAliasType;

Now that we have our classes loaded we will create a text format and a text field and then add the format to the new text field.

var format:TextFormat = new TextFormat();
format.font = ‘myFont’;
format.color = 0×333333;
var myText:TextField = new TextField();
myText.text = ‘Some Filler Text’;
myText.embedFonts = true;
myText.antiAliasType = AntiAliasType.ADVANCED;
myText.setTextFormat(format);

And there you go. You now have textfield using custom font.

Known Problems

-I am using Flash CS3 on my Macbook Pro and I found that if you add a font to your computer in the fonts folder while Flash is open the font may not be displayed. Instead what was happening to me was I was getting a default font. This made me stressed as nobody was having this problem. But all you have to do is close Flash and reopen Flash and your font will work now. There is some refreshing issue that Flash has with this process in CS3.

I will be posting any other issues with possible solutions.

If you liked this post, you might also like…

How to change a textfield’s alpha in Actionscript 3.0

Simple Image Gallery in Flash CS4

Share:
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
  • StumbleUpon
  • Technorati
  • Twitter