Using a grid fit type

When you use advanced anti-aliasing on a text field, three types of grid fitting are available:

none  Specifies no grid fitting. Horizontal and vertical lines in the glyphs are not forced to the pixel grid. This setting is usually good for animation and for large font sizes.

pixel Specifies that strong horizontal and vertical lines are fit to the pixel grid. This setting works only for left-aligned text fields. This setting generally provides the best legibility for left-aligned text.

subpixel Specifies that strong horizontal and vertical lines are fit to the subpixel grid on an LCD monitor. The subpixel setting is generally good for right-aligned and center-aligned dynamic text, and it is sometimes a useful trade-off for animation versus text quality.

The following example shows how to set a grid fit type on a text field by using ActionScript.

To set a grid fit type on a text field:

  1. Create a new Flash document and save it as gridfittype.fla.
  2. Select New Font from the pop-up menu in the upper-right corner of the Library panel.
  3. Select Arial font from the Font drop-down menu and set the font size to 10 points.
  4. Type the font name Arial-10 (embedded) in the Name text box and click OK.
  5. Right-click the font symbol in the library and select Linkage to open the Linkage Properties dialog box.
  6. Set the linkage identifier to Arial-10, and then select the Export for ActionScript and Export in First Frame check boxes.
  7. Click OK.
  8. Add the following code to Frame 1 of the main Timeline:
    var my_fmt:TextFormat = new TextFormat();
    my_fmt.size = 10;
    my_fmt.font = "Arial-10";
    var h:Number = Math.floor(Stage.height / 3);
    
    this.createTextField("none_txt", 10, 0, 0, Stage.width, h);
    none_txt.antiAliasType = "advanced";
    none_txt.embedFonts = true;
    none_txt.gridFitType = "none";
    none_txt.multiline = true;
    none_txt.setNewTextFormat(my_fmt);
    none_txt.text = "loading...";
    none_txt.wordWrap = true;
    
    this.createTextField("pixel_txt", 20, 0, h, Stage.width, h);
    pixel_txt.antiAliasType = "advanced";
    pixel_txt.embedFonts = true;
    pixel_txt.gridFitType = "pixel";
    pixel_txt.multiline = true;
    pixel_txt.selectable = false;
    pixel_txt.setNewTextFormat(my_fmt);
    pixel_txt.text = "loading...";
    pixel_txt.wordWrap = true;
    
    this.createTextField("subpixel_txt", 30, 0, h*2, Stage.width, h);
    subpixel_txt.antiAliasType = "advanced";
    subpixel_txt.embedFonts = true;
    subpixel_txt.gridFitType = "subpixel";
    subpixel_txt.multiline = true;
    subpixel_txt.setNewTextFormat(my_fmt);
    subpixel_txt.text = "loading...";
    subpixel_txt.wordWrap = true;
    
    var lorem_lv:LoadVars = new LoadVars();
    lorem_lv.onData = function(src:String):Void {
        if (src != undefined) {
            none_txt.text = "[antiAliasType=none]\n" + src;
            pixel_txt.text = "[antiAliasType=pixel]\n" + src;
            subpixel_txt.text = "[antiAliasType=subpixel]\n" + src;
        } else {
            trace("unable to load text file");
        }
    };
    lorem_lv.load("http://www.helpexamples.com/flash/lorem.txt");
    

    The preceding ActionScript code can be separated into five sections. The first section defines a new text format object that specifies two properties, size and font. The font property refers to the linkage identifier of the font symbol currently in the document library. The second, third, and fourth sections of code each create a new dynamic text field on the Stage and set some common properties: antiAliasType (which must be set to advanced), embedFonts (set to true), multiline, and wordWrap. Each section also applies the text format object created in an earlier section, and sets the grid fit type to normal, pixel, or subpixel. The fifth, and final, section creates a LoadVars instance, which loads the contents of an external text file into each of the text fields that you created with code.

  9. Save the document and select Control > Test movie to test the SWF file.

    Each text field should be initialized with the value "loading...". After the external text file is successfully loaded, each text field displays some formatted sample text using a different grid-fit type.

    TIP

     

    The advanced anti-aliasing technology uses grid fitting only at 0ยบ rotation.


Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00000904.html