...ndid, the somewhat small but happy love child of Nicolás Delfino. A company specialized in interactive websites and rich media applications, knee deep in actionscript and down with jazz...

AS3 Embedding fonts
Posted on: December 12th, 2010

I´m sure there is more than one way of doing this, but this is how I go about embedding fonts in Flash projects when using the Flash IDE for exporting and an external editor for coding.

Inside the flash IDE:

1. Adding the font:

I always start with setting up my font, so in the library panel, I choose add new Font:

2. Naming and embedding

Step two is to name your font, if the project at hand only uses one font, I usually call it “ProjectFont”:

3. Exporting:

Step three is simply to export your font so that you can call it from your editor.

In the Actionscript tab, check the “Export for Actionscript” checkbox, you´ll see that Flash automatically populates the Class field giving the class the same name as the name you specified for the font.

Inside your favorite editor

Setting up your textfield is easy:

	import flash.display.Sprite;
	import flash.text.AntiAliasType;
	import flash.text.Font;
	import flash.text.GridFitType;
	import flash.text.TextField;
	import flash.text.TextFormat;

	public class CustomFontExample extends Sprite
		private var _t_format	:TextFormat = new TextFormat();
		private var _tf			:TextField = new TextField();
		private var _customFont	:Font = new ProjectFont();

		public function CustomFontExample()
			// textformat:

			t_format.font 			= _customFont.fontName;
			t_format.size 			= 15;
			t_format.color 			= 0x000000;

			// remember that if you exported your font as bold you need
			// to set the bold property of your textformat to true:

			t_format.bold 			= true;

			// textfield:

			_tf.gridFitType 		= GridFitType.SUBPIXEL;
			_tf.antiAliasType 		= AntiAliasType.ADVANCED;
			_tf.thickness 			= 50;
			_tf.sharpness 			= -200;
			_tf.multiline 			= true;
			_tf.wordWrap 			= true	

			// set the embedFonts property to true:

			_tf.embedFonts 			= true;
			_tf.defaultTextFormat 	= t_format;

			_tf.text = "Hello World";


/ Nicolas

Tags: , ,

Leave a Reply