EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 390

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
390 Working with Text and Strings
You can find sample source files that demonstrate how to work with text fields using
ActionScript. The source files are called textfieldsA.fla and textfieldsB.fla, and you can find
them in the Samples folder on your hard disk:
In Windows, browse to boot drive\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\TextFields.
On the Macintosh, browse to Macintosh HD/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/TextFields.
Changing a text field’s dimensions at runtime
You may need to get or set a text field’s dimensions dynamically at runtime, rather than in the
authoring environment. The next example creates a text field on a timeline and sets its initial
dimensions to 100 pixels wide by 21 pixels high. Later, the text field is resized to 300 pixels
wide by 200 pixels high, and it is repositioned to the center of the Stage.
To resize a text field using ActionScript:
1. Create a new Flash document and save it as resizeText.fla.
2. Add the following ActionScript to Frame 1 of the Timeline:
this.createTextField("my_txt", 10, 0, 0, 100, 21);
my_txt.border = true;
my_txt.multiline = true;
my_txt.text = "Hello world";
my_txt.wordWrap = true;
my_txt._width = 300;
my_txt._height = 200;
my_txt._x = (Stage.width - my_txt._width) / 2;
my_txt._y = (Stage.height - my_txt._height) / 2;
3.
Save the Flash document and select Control > Test Movie to see the results in the authoring
environment.
The previous example resized a dynamically created text field to 300 pixels by 200 pixels at
runtime, but when you load content from an external website and are not sure how much
content will be returned, this technique may not be suitable for your needs. Fortunately, Flash
includes a
TextField.autoSize property, which you can use to automatically resize a text
field to fit its contents. The following example demonstrates how you can use the
TextField.autoSize property to resize the text field after text is added to the text field.

Table of Contents

Related product manuals