ActionScript 3. 0 Cookbook
Authors: Lott J. Schall D. Peters K.
Published year: 2007
Pages: 157-159/351
Buy this book on amazon.com >>

Recipe 9.28. Applying Advanced Anti-Aliasing

Problem

You want to have more precise control over anti-aliasing of text.

Solution

Embed the font, set the antiAliasType property of the text field to flash.text.AntiAliasType.ADVANCED , and set the gridTypeFit and sharpness properties.

Discussion

By default, text displays with normal anti-aliasing settings. For most fonts at sizes 10 and higher the normal anti-aliasing settings make for legible text. However, for smaller font sizes and for certain fonts, the normal anti-aliasing settings make the text less than legible. In those cases, you can set the anti-alias type for the text field to advanced and use the gridFitType and sharpness properties to more precisely control how the text is rendered.

To enable advanced anti-alias settings for a text field, you must use embedded fonts. See Recipe 9.17 for more details on how to embed fonts.


The TextField.antiAliasType property accepts one of the flash.text.AntiAliasType constants of NORMAL (default) or ADVANCED . Set the value of the property to ADVANCED for a text field if you want to enable more precise anti-alias settings:

field.antiAliasType = AntiAliasType.ADVANCED;

The gridFitType property determines how the font outlines snap to whole pixels on the screen. The possible values are the NONE , PIXEL , and SUBPIXEL constants of the flash.text.GridFitType class. The default value of NONE means that the text does not snap to whole pixels. That can cause text to appear blurry at smaller font sizes. The PIXEL setting snaps horizontal and vertical lines of the font outlines to whole pixels on the screen. The PIXEL setting works only when text is left-aligned. If you want center- or right-aligned text to snap to pixels, use the SUBPIXEL setting.

field.gridFitType = GridTypeFit.PIXEL;

The sharpness property ranges from -400 to 400, with a default value of 0; it determines how crisply the edges of the font outlines are rendered. The lower the number, the less sharply the fonts are rendered. The greater the number, the more sharply the fonts are rendered. If the text is not legible because it appears blurry, and you've already set the gridFitType to PIXEL or SUBPIXEL , then increase the sharpness value.

See Also

Recipe 9.17



Recipe 9.29. Replacing Text

Problem

You want to replace text.

Solution

Use the replaceSelectedText( ) method to replace the highlighted text and replaceText( ) to replace a range of text.

Discussion

The replaceSelectedText( ) method enables you to replace the selected text in a text field. Simply pass the method the string to use as the replacement text. For the method to work, the text field must have focus:

_field.replaceSelectedText("new text");

Use the replaceText( ) method to replace text within a text string given a starting and ending index. The following replaces the text from index 100 to index 150, with the new string specified by the third parameter:

_field.replaceText(100, 150, "new text");



Recipe 9.30. Retrieving a List of System Fonts

Problem

You want to retrieve a list of fonts on the user 's system.

Solution

Use the static TextField.fontList property.

Discussion

When you want to use system fonts (rather than embedding the font or using a font group ), first determine which fonts the user has installed. You can retrieve an array of system fonts on the user's computer with the TextField.fontList property.

trace(TextField.fontList);

Retrieving the list of available system fonts simply yields an array of strings. To apply a font to the text, you'll have to use one of the techniques discussed in Recipe 9.16.


ActionScript 3. 0 Cookbook
Authors: Lott J. Schall D. Peters K.
Published year: 2007
Pages: 157-159/351
Buy this book on amazon.com >>

Similar books on Amazon