One of my recent discoveries in the mysterious wonders of embedding fonts in Flash, is that it has changed ever so slightly – but enough to make me pull my hair off (once again) to figure out WHY DOES MY FONT NOT SHOW UP! Gaaaawd!

And so I give you the ANSWER! The reason is:

The newest Flash Player (FP10 as of this writing) has new TextField primitive classes in the flash.text.engine.* package. These, from what it seems, are encouraged to be used by Adobe. Yes they have far more control over text flow control, but for multiple developers out there…. we’re just not ready to move that step up, yet!

So with this assumption from Adobe, that everyone will use their new fancy TextBlock / TextLine / TextElement classes, they’ve decided to slip in some new default values in the [Embed] tag:

I present you: embedAsCFF

For embedding fonts that will be used in a classic TextField object, use the following declaration:

//A Windows Font example:
[Embed(source = "C:/Windows/Fonts/ARIAL.TTF",
	fontName = '_arial',
	fontStyle = "regular",
	embedAsCFF="false", //<-- This line MUST be set!
	mimeType="application/x-font")]

If you are loading the font from a separate SWF file, to make the parent one “aware” that it can be used for embedding you will have to register it with the following:

Font.registerFont( FONT_CLASS ); //Notice: Class, and not Instance

To apply the font to your textfield, your best bet is to use the font-instance’s name:

var format:TextFormat =	new TextFormat();
format.font =			myFont.fontName;
format.bold =			myFont.fontStyle.indexOf("bold")>-1;
format.color =			0x000000;
format.size =			12;

var field:TextField =		new TextField();
field.embedFonts =		true;  //Don't forget to set this!
field.selectable =		false;
field.width =			200;
field.height =			200;
field.border =			true;
field.multiline =		true;
field.wordWrap =		true;
field.x =			1;
field.y =			1;
field.defaultTextFormat =	format;
field.text =			"this may contain some very looooooooooong words!";

If you want to confirm that you have properly registered the font, you can verify it with:

var fonts:Array = Font.enumerateFonts(false);
var font:Font;
var output:String = "";
for(var f:int=fonts.length; --f>=0;) {
  font = fonts[f];
  output += font.fontName, font.fontStyle, font.fontType].join(", ");
}

trace(output);

UPDATE:

A very useful tool for generating the right set of Unicode range to embed can be found here:

Unicode range generator for AS3

It’s very useful to crunch-down the kilobytes (sometimes even megabytes) by eliminating the glyphs you don’t need for certain fonts.