About text fields
385
■
On the Macintosh, browse to
Macintosh HD
/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/TextFields.
Assigning text to a text field at runtime
When you build applications with Flash, you may want to load text from an external source,
such as a text file, an XML file, or even a remote web service. Flash provides a great deal of
control over how you create and display text on the Stage, such as supporting text that is
HTML formatted, plain text, XML formatted text, and external style sheets. Or you can use
ActionScript to define a stylesheet.
To assign text to a text field, you can use the
TextField.text
or the
TextField.htmlText
property. Or, if you entered a value in the variable text field in the Property inspector, you can
assign a value to the text field by creating a variable with the specified name. If you use version
2 of Macromedia Components Architecture in your Flash document, you can also assign
values by creating bindings between components.
The following exercise assigns text to a text field at runtime.
To assign text to a text field at runtime:
1.
Using the Text tool, create a text field on the Stage.
2.
With the text field selected, in the Property inspector (Window > Properties > Properties),
select Input Text from the Text Type pop-up menu, and enter
headline_txt
in the Instance
Name text box.
Instance names must consist only of letters, numbers, underscores (_), and dollar
signs ($).
3.
Select Frame 1 of the Timeline, and open the Actions panel (Window > Actions).
4.
Type the following code in the Actions panel:
headline_txt.text = "New articles available on Developer Center";
5.
Select Control > Test Movie to test the Flash document.
You can also create a text field with ActionScript, and then assign text to it. Type the following
ActionScript on Frame 1 of the Timeline:
this.createTextField("headline_txt", this.getNextHighestDepth(), 100, 100,
300, 20);
headline_txt.text = "New articles available on Developer Center";
This code creates a new text field with the instance name
headline_txt
. The text field is
created at the next highest depth, at the
x
and
y
coordinates of 100, 100, with a text field
width of 200 pixels and a height of 20 pixels. When you test the SWF file (Control > Test
Movie), the text “New articles available on Developer Center
”
appears on the Stage.
Содержание 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...