About text fields
391
To automatically resize text fields based on content:
1.
Create a new Flash document and save it as
resizeTextAuto.fla
.
2.
Add the following code to Frame 1 of the main Timeline:
this.createTextField("my_txt", 10, 10, 10, 160, 120);
my_txt.autoSize = "left";
my_txt.border = true;
my_txt.multiline = true;
my_txt.text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.";
my_txt.wordWrap = true;
3.
Save the Flash document and select Control > Test Movie to view the Flash document in
the authoring environment.
Flash resizes the text field vertically so that all the content can be displayed without being
cropped by the text field boundaries. If you set the
my_txt.wordWrap
property to
false
,
the text field resizes horizontally to accommodate the text.
To enforce a maximum height on the auto-sized text field (so that the text field height
doesn’t exceed the boundaries of the Stage), use the following code.
if (my_txt._height > 160) {
my_txt.autoSize = "none";
my_txt._height = 160;
}
You must add some scrolling functionality, such as a scroll bar, to allow users to view the
remainder of the text. Alternatively, you can roll the mouse pointer over the text; this method
is often adequate while testing this code.
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.
NO
T
E
If you paste this code directly into the Actions panel from some versions of Flash
Help, you may encounter line breaks in the long text string. In this case, the code
won’t compile. If you encounter this situation, enable Hidden Characters on the pop-
up menu of the Actions panel, and then remove the line break characters in the long
text string.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...