Problems embedding multiple members of the same font-family in Actionscript 3.0

I came across a problem the other day which it turns out is quite common. Normally when I am dealing with fonts in Actionscript I simple create a new font in the library and call that via the SWC in FDT. However, it turns out that if I make a font called Didot_Regular and Didot_Bold and tick the appropriate ‘Bold’ and ‘Regular’ boxes my compiled SWF fails to differentiate between the two.

The solution is create your fonts in a Class and compile this as a separate SWC or SWF. Here’s how :

package fonts {
	
	import flash.display.Sprite;

	/**
	 * @author Dan
	 */
	 
	public class MyFonts extends Sprite {
        
		[Embed(source="/../fonts/Didot.ttc", fontName="Didot", fontStyle="normal", fontWeight="bold", mimeType="application/x-font-truetype")]
		public static var DidotBold		:	Class;
		
		[Embed(source="/../fonts/Didot.ttc", fontName="Didot", fontStyle="normal", fontWeight="normal", mimeType="application/x-font-truetype")]
		public static var Didot			:	Class;
		
	}
}

Now compile this as a SWF or as a SWC library and then use the fonts as normal :


			var tf : TextFormat = new TextFormat();
			tf.font = new MyFonts_DidotBold().fontName;
			tf.bold = true;
			tf.size = 18;
			tf.color = 0xFFFFFF;

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 )

Connecting to %s