MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 385

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

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
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
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
or the
TextField.text
headline_txt
appears on the Stage.
"
TextField.htmlText
. The text field is
About text fields
385

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents