Flash AS3 Font Embedding Issue - A Problem with Grandchildren?

I’ve been working on a project that was causing me endless frustration with Flash font embedding.
Basically, I had a Main.swf that I had embedded a font in. It has a child SWF, say “child.swf”, that gets loaded. Then that child.swf, used a class file which created a loaded in a photo and created a dynamic text field, so I thought of it as a grandchild of Main.swf.
In the ‘grandchild’ the dynamic text field is formatted to embed the font that is in Main.swf. Since I wanted to be able access that font from Main.swf everywhere, I first made a new Font in my Library and checked “Export for ActionScript” and “Export on frame 1”. I also put this line in my Main.as document class file: 

Font.registerFont(CenturyGothic);

I thought all would be fine. In my ‘grandchild’ that created the dynamic text field, I ran the following testing function, showEmbeddedFonts, to see what fonts were there.

public function showEmbeddedFonts ():void {
	trace("========Embedded Fonts========");
	var fonts:Array = Font.enumerateFonts();
	fonts.sortOn("fontName", Array.CASEINSENSITIVE);

	for (var i:int = 0; i < fonts.length; i++) {
		trace(fonts[ i ].fontName + ", " + fonts[ i ].fontStyle);
	}
}


My trace statement confirmed that the font I’d registered in Main.swf was there. The trouble was actually having it be seen on screen. I didn’t realize it wasn’t embedding properly for quite a while. Since the font is active on my machine, when I tested the file, it would always appear as it was intended. The problem was only evident when I went to an outside machine and saw my styled text was not displaying properly. It looked like the default _serif text, a device font, displayed by Flash instead.
What was going on? My trace seemed to indicate the font should be available, but it just didn’t seem to be working. After a lot of searching, I came across the 2 following posts:

  • http://craiggrummitt.blogspot.com/2009/06/i-once-found-that-when-as3-flash.html
  • http://forums.adobe.com/thread/453351?tstart=0

Ultimately what I’ve ended up doing is embedding the font in the ‘child.swf’ in addition to the ‘Main.swf’ file. In ‘child.swf’ I made sure to include the same ActionScript ‘Font.registerFont(CenturyGothic);’ that was present in the Main.as file. This solved the problem of the font not displaying, but it’s bloated all swf that are siblings to ‘child.swf’. 
It seems like chlidren can see a font it’s parent has added to the global list of fonts, but grandchlldren lose access to them. 

There are no comments to this post.

Commenting is not available in this channel entry.

Twitter Feed

John Morton talking on Twitter




Meanwhile on Instagram… //

My latest shot from Instagram.