Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Working with Text and Strings > About text layout and formatting > About formatting anti-alias text | |||
Flash introduces two properties that you can use when you format text fields with advanced anti-aliasing enabled: sharpness and thickness. Sharpness refers to the amount of aliasing that is applied to the text field instance. A high value for sharpness makes the embedded font edge appear jagged and sharp. Setting sharpness to a lower value makes the font appear softer, with more blurring. Setting a font's thickness is similar to enabling bold formatting for a text field. The higher the thickness, the bolder the font appears.
The following example dynamically loads a text file and displays text on the Stage. Moving the mouse pointer along the x axis sets the sharpness between -400 and 400. Moving the mouse pointer along the y axis sets the thickness between -200 and 200.
To modify a text field's sharpness and thickness:
var my_fmt:TextFormat = new TextFormat();
my_fmt.size = 24;
my_fmt.font = "Arial-24";
this.createTextField("lorem_txt", 10, 0, 20, Stage.width, (Stage.height - 20));
lorem_txt.setNewTextFormat(my_fmt);
lorem_txt.text = "loading...";
lorem_txt.wordWrap = true;
lorem_txt.autoSize = "left";
lorem_txt.embedFonts = true;
lorem_txt.antiAliasType = "advanced";
this.createTextField("debug_txt", 100, 0, 0, Stage.width, 20);
debug_txt.autoSize = "left";
debug_txt.background = 0xFFFFFF;
var lorem_lv:LoadVars = new LoadVars();
lorem_lv.onData = function(src:String) {
lorem_txt.text = src;
}
lorem_lv.load("http://www.helpexamples.com/flash/lorem.txt");
var mouseListener:Object = new Object();
mouseListener.onMouseMove = function():Void {
lorem_txt.sharpness = (_xmouse * (800 / Stage.width)) - 400;
lorem_txt.thickness = (_ymouse * (400 / Stage.height)) - 200;
debug_txt.text = "sharpness=" + Math.round(lorem_txt.sharpness) +
", thickness=" + Math.round(lorem_txt.thickness);
};
Mouse.addListener(mouseListener);
This ActionScript code can be separated into five key sections. The first section of code defines a new TextFormat instance that will be applied to a dynamically created text field. The next two sections create two new text fields on the Stage. The first text field, lorem_txt, applies the custom text formatting object created earlier, enables embedded fonts, and sets the antiAliasType property to true. The second text field, debug_txt,displays the current sharpness and thickness values for the lorem_txt text field. The fourth section of code creates a LoadVars object, which is responsible for loading the external text file and populating the lorem_txt text field. The fifth, and final, section of code defines a mouse listener that is called whenever the mouse pointer moves on the Stage. The current values for sharpness and thickness are calculated based on the current position of the mouse pointer on the Stage. The sharpness and thickness properties are set for the lorem_txt text field, and the current values are displayed in the debug_txt text field.
Move the mouse pointer along the x axis to change the text field's sharpness. Move the mouse pointer from left to right to cause the sharpness to increase and appear more jagged. Move the mouse pointer along the y axis to cause the text field's thickness to change.
For more information on using anti-alias text in a SWF file, see Setting anti-alias with ActionScript, Font rendering options in Flash, and Using a grid fit type.
For a sample source file, aliasing.fla, that shows how to apply and manipulate anti-aliasing text in an application, see the Flash Sample page at www.adobe.com/go/learn_fl_samples. Download and decompress the Samples zip file and navigate to the ActionScript 2.0/Advanced Anti-Aliasing folder to access the sample. You use the advanced anti-aliasing technology to create small text that's highly legible. This sample also demonstrates how text fields can scroll quickly and smoothly when you use the cacheAsBitmap property.
|
|
|
|