User Guide

Sending and loading variables to and from a remote source 277
For example, the following ActionScript loads the variables from the file myData.txt into the
movie clip
loadTarget_mc. An onData() handler assigned to the loadTarget_mc instance uses
the variable
lastSiteVisited, which is loaded from the file myData.txt. The following trace
actions appear only after all the variables, including
lastSiteVisited, are loaded:
this.createEmptyMovieClip("loadTarget_mc", this.getNextHighestDepth());
this.loadTarget_mc.onData = function() {
trace("Data Loaded");
trace(this.lastSiteVisited);
};
loadVariables("myData.txt", this.loadTarget_mc);
If you use the XML.load(), XML.sendAndLoad(), and XMLSocket.connect() methods, you
should define a handler that will process the data when it arrives. This handler is a property of an
XML or XMLSocket object to which you assign a function you defined. The handlers are called
automatically when the information is received. For the XML object, use
XML.onLoad() or
XML.onData(). For the XMLSocket object, use XMLSocket.onConnect().
For more information, see “Using the XML class” on page 280 and “Using the XMLSocket class
on page 284. For more information on using LoadVars to send and load data that can be
processed after the data is received, see “Using the LoadVars class” on page 278.
Using HTTP to connect to server-side scripts
The
loadVariables(), loadVariablesNum(), getURL(), loadMovie(), loadMovieNum()
functions and the
MovieClip.loadVariables(), MovieClip.loadMovie(), and
MovieClip.getURL() methods can communicate with server-side scripts using HTTP or
HTTPS protocols. These functions and methods send all the variables from the Timeline to
which the function is attached. When used as methods of the MovieClip object,
loadVariables(), getURL(), and loadMovie() send all the variables of the specified movie clip;
each function (or method) handles its response as follows:
The getURL() function returns any information to a browser window, not to Flash Player.
The loadVariables() methods loads variables into a specified Timeline or level in Flash
Player.
The loadMovie() methods loads a SWF file into a specified level or movie clip in Flash Player.
When you use
loadVariables(), getURL(), or loadMovie(), you can specify
several parameters:
URL is the file in which the remote variables reside.
Location is the level or target in the SWF file that receives the variables. (The getURL()
function does not take this parameter.)
For more information about levels and targets, see “Multiple Timelines and levels” in Using
Flash.
Variables sets the HTTP method, either GET (appends the variables to the end of the URL)
or
POST (sends the variables in a separate HTTP header), by which the variables are sent.
When this parameter is omitted, Flash Player defaults to
GET, but no variables are sent.