Loading variables by using LoadVars
The LoadVars class also lets you load variables in a URL-encoded format, similar to passing
variables in the query string in a web browser. The following example demonstrates how to
load a remote text file into a SWF file and display its variables,
To load variables from a text file by using LoadVars:
1.
Create a new Flash document and save it as loadvarsVariables.fla.
2.
Add the following code 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.onLoad = function (success:Boolean):Void {
if (success) {
my_txt.text = "dayNames: " + lorem_lv.dayNames + "\n\n";
my_txt.text += "monthNames: " + lorem_lv.monthNames;
} else {
my_txt.text = "Unable to load external file.";
}
}
/* contents of params.txt:
&monthNames=January,February,...&dayNames=Sunday,Monday,...
*/
lorem_lv.load("http://www.helpexamples.com/flash/params.txt");
3.
Save the Flash document and select Control > Test Movie from the main menu.
Because you are using the
Flash parses out the variables and creates variables within the LoadVars object instance.
The external text file contains two variables,
contain strings.
For information on security, see
396
Working with Text and Strings
LoadVars.onLoad()
monthNames
Chapter 17, "Understanding Security."
monthNames
method instead of
LoadVars.onData()
and
dayNames
and
.
dayNames
,
, which both
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?