The easiest way to create outlined dynamic text in AS3 is to apply an instance of the GlowFilter to the TextField in which you want all individual letters of text to be outlined. Simply choose low blur parameters and large strength parameter for the GlowFilter: new GlowFilter(0x000000,1.0,2.0,2.0,10). In this tip we show exactly how to do it.
Download the very well-commented source fla file corresponding to the effect above:
Comments and Code
Below is the Timeline code for the Flash movie presented here and comments.
We create two instances of TextField, field1 and field2 and position them on the stage. By default, they are dynamic TextFields. We also create an instance of TextFormat to assign format to field1 and field2.
var field1:TextField=new TextField();
var field2:TextField=new TextField();
var format:TextFormat=new TextFormat();
field1.text="OUTLINED TEXT SHOWS ON EVERY BACKGROUND.";
field2.text="OUTLINE IS OBTAINED BY APPLYING A PROPER GLOW FILTER TO A TEXT FIELD.";
The text outline is created by assigning GlowFilter to each text field. The first parameter of GlowFilter's constructor is the color of the outline. We chose black; you can replace is by any other color to get colored outlines. The second parameter is the alpha of the outline; we chose 1. The third and fourth parameters are blurX and blurY. Valid values are between 0 and 255, the default is 6.0 for both. We chose smaller blur values: 2.0. We decreased blur because we don't really want to create a glowing effect. We want outline. The next parameter is 'strength' of GlowFilter. The valid values are between 0 and 255; the default is 2. We chose higher strength: 10. The higher strength, the thicker outline. Finally, we assign filter's quality to be 'MEDIUM'. You can choose 'LOW', or 'HIGH', but 'MEDIUM' works best for creating outline. MEDIUM quality means that the filter is applied twice. If you choose HIGH, the filter is applied three times giving thicker outline.
var outline:GlowFilter=new GlowFilter(0x000000,1.0,2.0,2.0,10);
The same trick can be used for outlining other DisplayObjects. In most of our photo galleries thumbnails show outline when the user mouses over them. The colored outline is created using the GlowFilter as demonstrated above. See, for example: 3D Cylindrical Photo Gallery in AS3 Flash - Outside View