Connecting with External Sources > Sending and loading variables to and from a remote source > Using the LoadVars object |  |

Using the LoadVars object

You can use the LoadVars object instead of `loadVariables` to transfer variables between a Flash movie and a server. The LoadVars object 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` method and sets variables in the target. You can use LoadVars to obtain error information and progress indications and to stream the data while it downloads.

The LoadVars object is similar to the XML object; it uses the methods `load`, `send`, and `sendAndLoad` to initiate communication with the server. The main difference between the LoadVars and XML objects 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 new instance of the LoadVars object to call its methods. This instance is a container to hold the loaded data.

To load data with the LoadVars object:

1 | Choose a frame, button, or movie clip to which to assign the action.
2 | Choose Window > Actions to open the Actions panel if it isn't already open.
3 | In the Actions toolbox, click the Actions category, click Variables, and double-click the `set variable` action to add it to the Script pane.
4 | In the Variable parameter box, enter an instance name for the new object, for example, `myLoadVars`.
5 | With the insertion point in the Value parameter box, from the Actions toolbox, click the Objects category, then click Client/Server, click LoadVars, and double-click `new LoadVars` to add it to the Script pane. Select the Expression box.
| The code should look like this:
    myLoadVars = new LoadVars();
6 | In the Actions toolbox, click the Objects category, click Client/Server, LoadVars, and Methods, and double-click the `load` method to add it to the Script pane.
7 | In the Object parameter box, enter the instance name of the LoadVars object into which the data will load—in this example, `myLoadVars`.
8 | In the Parameters box, enter the URL from which to download data.
| The URL must be enclosed in quotation marks, for example, "`http://www.myserver.com/data.txt`". The finished code should look like this:
    myLoadVars = new LoadVars();
    myLoadVars.load("http://www.myserver.com/data.txt");

For more information, see LoadVars (object) in the ActionScript Dictionary.