...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...


Posts Tagged ‘tips’

AS3 Custom anti-alias

Posted on: December 13th, 2010

Ever wanted to change the thickness and sharpness settings through actionscript but didn´t know how?

Flash IDE:

To edit these settings within Flash you just need to click on your textfield and choose “Custom anti-alias” in the Anti-alias dropdown:

The actionscript way:

Doing the same thing in code requires a few steps and it can get a bit repetative, writing a class to handle stuff like this is maybe a good idea, anyway:

package
{
	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 CustomAntiAliasExample extends Sprite
	{
		private var _t_format	:TextFormat = new TextFormat();
		private var _tf			:TextField = new TextField();
		private var _customFont	:Font = new ProjectFont();

		public function CustomAntiAliasExample()
		{
			t_format.font 			= _customFont.fontName;
			t_format.size 			= 15;
			t_format.color 			= 0x000000;
			t_format.bold 			= true;

			// -------------------------------------> ANTI ALIAS PART:

			_tf.gridFitType 		= GridFitType.SUBPIXEL;
			_tf.antiAliasType 		= AntiAliasType.ADVANCED;

			// thickness:
			_tf.thickness 			= 50;
			// sharpness:
			_tf.sharpness 			= -200;

			// -------------------------------------------------------

			_tf.embedFonts 			= true;
			_tf.defaultTextFormat 	= t_format;
			_tf.text = "Hello World";
			addChild(_tf);
		}
	}
}

Examples:

/ Nicolas

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:

package
{
	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";

			addChild(_tf);
		}
	}
}

/ Nicolas