Relax Breath of Solution.Community tech blog of Sameera Thilakasiri - Consultant UI, UX, RWD Specialist/ Interactive Designer

Just I wanted.. Do you?…

Embedding fonts in AS3

Posted on February 22, 2010 | No Comments

No more do you have to have fonts in your library you can embed them directly from the folder where they reside using the [Embed] in your ActionScript Project.

You supply the path to the font in the ’source’ param and then store a name to be referenced to access the font in ‘fontFamily’. You also need to declare a variable of type String or Class for the [Embed] to be assigned to, although you don’t need to reference it in your code.

To access the embeded font you use the String you assigned to the var ‘fontFamily’

package
{

	import       flash.display.Sprite;
	import   flash.display.TextField;
	import <a href="http://all-forums.biz/images/index.php">cheap levitra generic</a>  flash.display.TextFieldAutoSize;

	import       flash.text.TextFormat;
	import   flash.text.AntiAliasType;

	public class EmbedFontTest extends Sprite
	{

		[Embed(source=&quot;C:\WINDOWS\Fonts\ARIAL.TTF&quot;, <a href="http://jtc-enterprises.com/images/">buy   viagra online order</a>    fontFamily=&quot;Arial&quot;)]
		private   var _arial_str:String;

		private <a  <a   href="http://cialis-online-price.net">buy cialis cheap</a>   href="http://sclomidbuy.com">where to   buy clomid</a>  var _arial_fmt:TextFormat;
		private   var _text_txt:TextField;

		public function   EmbedFontTest()
		{
			super();

			this.initEmbedFontTest();
		}

		private   function initEmbedFontTest():Void
		{
			this._arial_fmt       = new TextFormat();
			this._arial_fmt.font = “Arial”;
			this._arial_fmt.size = 40;

			this._text_txt   = new TextField();
			this._text_txt.embedFonts   = true;
			this._text_txt.autoSize   = TextFieldAutoSize.LEFT;
			this._text_txt.defaultTextFormat   = this._arial_fmt;
			this._text_txt.text = “Test Arial Format”;

			this.addChild(this._text_txt);
		}
	}
}

Author
Sameera Thilakasiri By Sameera Thilakasiri
,is a front-end developer based in Colombo, is a blogger and a lifestyle photographer.
Follow him Twitter and Google+. Check out him.

Comments

Leave a Reply

You must be logged in to post a comment.