Integrating Flash with Web Applications > Sending and loading variables to and from a remote file > Using loadVariables, getURL, and loadMovie

Using loadVariables, getURL, and loadMovie

The loadVariables, getURL, and loadMovie actions all communicate with server-side scripts using the HTTP protocol. Each action sends all the variables from the Timeline to which the action is attached; each action handles its response as follows:

getURL returns any information to a browser window, not into the Flash Player.
loadVariables loads variables into a specified Timeline in the Flash Player.
loadMovie loads a movie into a specified level in the Flash Player.

When you use the loadVariables, getURL, or loadMovie actions, you can specify several arguments:

URL is the file in which the remote variables reside.
Location is the level or target in the movie that receives the variables.
For more information about levels and targets, see About multiple Timelines.
Note: The getURL action does not take this argument.
Variables sets the HTTP method, either GET or POST, by which the variables will be sent.

For example, if you wanted to track the high scores for a game, you could store the scores on a server and use a loadVariables action to load them into the movie each time someone played the game. The action might look something like this:

loadVariables("http://www.mySite.com/scripts/high_score.php", _root.scoreClip, GET);

This loads variables from the PHP script called high_score.php into the movie clip instance scoreClip using the GET HTTP method.

Any variables loaded with the loadVariables action must be in the standard MIME format application/x-www-urlformencoded (a standard format used by CGI scripts). The file that you specify in the URL argument of the loadVariables action must write out the variable and value pairs in this format so that Flash can read them.

The 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, this phrase defines several variables:

highScore1=54000&playerName1=rockin+good&highScore2=53455&playerName2=bonehelmet&highScore3=42885&playerName3=soda+pop

For more information on loadVariables, getURL, and loadMovie, see their entries in the ActionScript Dictionary.