Life as Clay

Flex Builder 3, AS 3, and embedding fonts on a Mac

leave a comment »


For whatever reason, the common examples for how to embed fonts using Actionscript 3 do not work on the Mac, when coding in Flex Builder 3. There are many examples for how to do this, on the web and in books, but they just don’t work on OS X. Bummer.

The good news is that I found a working example. The bad news is that it was in the Internet Archive. I’m reposting it here in case somebody comes along and needs assistance. Here is the link to the Internet Archive. Here’s the example described:

… here i will show you the way you can embed fonts in AS3 project without passing through SWF files.

First of all, I recommend you to use a AssetManager class to have an easy access to all you need (these includes fonts obviously!).

And now let’s see how can we build this class (we take for example that we must embed two different fonts)

public final class AssetManager
{
[Embed(source="/assets/fonts/Arista.ttf", fontName="arista")]
public static var arista:Class;

[Embed(source="/assets/fonts/kroe0656.ttf", fontName="kroeger")]
public static const kroeger:Class;
}

… now where we want to use these fonts we may write this …

import flash.text.Font;
Font.registerFont(AssetManager.arista);
var myTF:TextField = new TextField();
var tf:TextFormat = new TextFormat();
tf.size = 48;
tf.font = "arista";
myTF.embedFonts = true;
myTF.antiAliasType = AntiAliasType.ADVANCED;
myTF.defaultTextFormat = tf;
myTF.text = "Light the moon";

I hope this helps somebody!

Advertisements

Written by Clay

January 25, 2010 at 19:30

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: