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

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

To use LoadVars to populate a text field with external text:
1.
Create a new Flash document and save it as loadvarsText.fla.
2.
Add the following ActionScript to Frame 1 of the Timeline:
this.createTextField("my_txt", 10, 10, 10, 320, 100);
my_txt.autoSize = "left";
my_txt.border = true;
my_txt.multiline = true;
my_txt.wordWrap = true;
var lorem_lv:LoadVars = new LoadVars();
lorem_lv.onData = function (src:String):Void {
if (src != undefined) {
my_txt.text = src;
} else {
my_txt.text = "Unable to load external file.";
}
}
lorem_lv.load("http://www.helpexamples.com/flash/lorem.txt");
The first block of code in the previous snippet creates a new text field on the Stage and
enables multiline and word wrapping. The second block of code defines a new LoadVars
object that is used to load a text file (lorem.txt) from a remote web server and display its
contents into the my_txt text field created earlier.
3.
Save the Flash document and select Control > Test Movie to test the SWF file.
After a slight delay, Flash displays the contents of the remote file in the text field on
the Stage.
For information on security, see
Chapter 17, "Understanding Security."
About loading text and variables into text fields
395

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?

This manual is also suitable for:

Flash 8

Table of Contents