Creating Text

I l @ ve RuBoard

You can also create text fields from scratch using ActionScript. To do this, the primary command is createTextField , but you usually need to do much more to get the text field to look like you want.

The most basic example is to create a simple field and place some text in it. Here is how it looks:

 createTextField("myTextField",0,0,0,200,40); myTextField.text = "Hello World."; 

As you can see, createTextField has many parameters. The first is the name of the text field. The second is its level. The third and fourth parameters are the x and y location of the upper-left corner of the field. The last two parameters are the width and height of a field.

The second line of the preceding code sets the text property of the field, which changes the text inside it. The result is a simple "Hello World." that appears in the upper-left corner of the movie, using the default font and size . You can test it for yourself with 24simpletext.fla.

You can create a more elaborate text field using some special properties and a text format object. You can read more about the text format object in Hour 10, "Creating and Controlling Text."

Here is a more complex example. The text is displayed in the middle of the screen with a specific font, size, and color .

 createTextField("myTextField",0,0,170,550,60); myTextField.text = "Hello World!"; myTextField.embedFonts = true; myTextFormat = new TextFormat(); myTextFormat.font = "Arial"; myTextFormat.size = 48; myTextFormat.color = 0x330000; myTextFormat.align = "center"; myTextField.setTextFormat(myTextFormat); 

The field property embedFonts controls whether device fonts are used to render the text, or whether fonts added to the Library are used.

graphics/clock.gif

If you choose to add fonts to the Library and use them in ActionScript-created text fields, you must remember to set the font's Linkage properties so that it exports with the movie.


The text format properties are set so that the font is Arial, the size is 24, the color is a dark red, and the text alignment is centered. You must apply the format with the setTextFormat command after you set the text .

The movie 24complextext.fla is a great way to test different field and format settings. Consult the ActionScript documentation for the long list of properties of both fields and formats.

graphics/bulb.gif

You can also create input text fields with the createTextField command. You just need to set the type of the field to "input." You can set the variable of the field to a value so that ActionScript can easily access the information that the user enters.


I l @ ve RuBoard


Sams Teach Yourself Flash MX ActionScript in 24 Hours
Sams Teach Yourself Flash MX ActionScript in 24 Hours
ISBN: 0672323850
EAN: 2147483647
Year: 2002
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net