Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Working with Text and Strings > About loading text and variables into text fields > 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, monthNames and dayNames.
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");
Because you are using the LoadVars.onLoad() method instead of LoadVars.onData(), Flash parses out the variables and creates variables within the LoadVars object instance. The external text file contains two variables, monthNames and dayNames, which both contain strings.
For information on security, see Understanding Security.
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000889.html