User Guide

Sending and loading variables to and from a remote source 69
Using HTTP to connect to server-side scripts
The
getURL() function and the MovieClip.loadVariables(), MovieClip.loadMovie(), and
MovieClip.getURL() methods can communicate with server-side scripts using HTTP or
HTTPS protocols. When used as a method of the MovieClip object,
getURL() sends 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 Flash Player.
The loadMovie() methods loads a SWF file into a specified 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 target in the SWF file that receives the variables. (The getURL() function does
not take this parameter.)
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.
For example, if you want to track the high scores for a game, you could store the scores on a server
and use
loadVariables() to load them into the SWF file each time someone played the game.
The function call might look like the following example:
loadVariables("http://www.mySite.com/scripts/high_score.cfm", scoreClip, GET);
This example loads variables from the ColdFusion script called high_score.cfm into the movie
clip instance
scoreClip using the GET HTTP method.
Any variables loaded with the
loadVariables() function must be in the standard MIME format
application/x-www-form-urlencoded (a standard format used by CFM and CGI scripts). The file
you specify in the
URL parameter of loadVariables() must write out the variable and value pairs
in this format so that Flash can read them.This file can specify any number of variables; variable
and value pairs must be separated with an ampersand (
&), and words within a value must be
separated with a plus (
+). For example, the following phrase defines several variables:
highScore1=54000&playerName1=RGoulet&highScore2=53455&playerName2=
WNewton&highScore3=42885&playerName3=TJones
Note: You might need to URL-encode certain characters, such as the plus (+) or ampersand (&)
characters. For more information, see www.macromedia.com/support/flash/ts/documents/
url_encoding.htm.
For more information, see getURL(), the LoadVars class entry, and “Using the LoadVars class”
on page 69.
Using the LoadVars class
If you are publishing to Flash Player 6 or later and want more flexibility than
loadVariables()
offers, you can use the LoadVars class instead to transfer variables between a SWF file and a server.