Set the grid instance on a text field in Flash

Source: Internet
Author: User

Create a new Flash document and save it as a gridfittype.fla.
Select New Font from the pop-up menu in the upper-right corner of the library panel.
Select the Arial font from the Font drop-down menu and set the font size to 10 points.
Type the font name ARIAL-10 (embedded) in the Name text box, and then click OK.
Right-click the font symbol in the library and select link to open the Link Properties dialog box.
Set the link identifier to Arial-10, and then select the export for ActionScript and export on first frame check box.
Click OK.

Add the following code to frame 1th in the main timeline:

The code is as follows Copy Code

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", 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", 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", 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 ("/lorem.txt");


The ActionScript code above can be divided into five parts. The first section defines a new text-format object that specifies two property size and font. The Font property refers to the link identifier for a font symbol in the current document library. The second, third, and part four code creates a new dynamic text field on the stage and sets some common properties: Antialiastype (must be set to Advanced), Embedfonts (set to True), multiline, and WordWrap. Each part of the code also applies the text Format object created in the previous section of code and sets the grid fixed type to normal, pixel, or sub-pixel. The last part of the code, the fifth part, creates a loadvars instance that loads the contents of the external text file into individual text fields created in code.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.