MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual page 180

Actionscript reference guide
Hide thumbs Also See for FLASH MX 2004 - ACTIONSCRIPT:
Table of Contents

Advertisement

Using the LoadVars class
You can use the LoadVars class instead of
file and a server. The LoadVars class lets you send all the variables in an object to a specified URL
and load all the variables at a specified URL into an object. The response from the server triggers
the
LoadVars.onLoad()
error information and progress indications and to stream the data while it downloads.
The LoadVars class is similar to the XML class; it uses the methods
sendAndLoad()
LoadVars and XML classes is that the LoadVars data is a property of the LoadVars object, rather
than an XML DOM (Document Object Model) tree stored in the XML object.
You must create a LoadVars object to call its methods. This object is a container to hold the
loaded data.
The following procedure shows how to use a LoadVars object to load variables from a text file and
display those variables in a text field.
To load data with the LoadVars object:
In a text editor such as Notepad or SimpleText, create a text file and add the following text to
1
the text file:
day=11&month=July&year=2003
Save the file as date.txt.
2
In Flash, create a document.
3
Create a dynamic text field on the Stage and give it the instance name
4
Select Frame 1 in the Timeline and open the Actions panel (Window > Development Panels >
5
Actions) if it isn't already open.
Enter the following code in the Actions panel:
6
var dateVars = new LoadVars();
dateVars.onLoad = function(ok) {
if (ok) {
date_txt.text = dateVars.day+"/"+dateVars.month+"/"+dateVars.year;
}
};
dateVars.load("date.txt");
This code loads the variables in data.txt (
the text field
date_txt
Save the document as dateReader.fla to the same directory that contains date.txt (the text file
7
you saved in step 3).
Select Control > Test Movie to test the document.
8
For more information, see the
on page
205.
180
Chapter 10: Working with External Data
method and sets variables in the target. You can use LoadVars to obtain
to initiate communication with the server. The main difference between the
.
LoadVars class
to transfer variables between a SWF
loadVariables()
,
,
), then formats and displays them in
day
month
year
entry in
Chapter 12, "ActionScript Dictionary,"
,
, and
load()
send()
.
date_txt

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?

Questions and answers

Table of Contents