19.2. Sending Variables

Problem

You want to send variables to the server at runtime.

Solution

Use a LoadVars object. Call the send( ) method. Note that the send( ) method doesn’t send values and always opens the response in a browser window. Optionally, to both send and load variables or to send variables transparently use the sendAndLoad( ) method.

Discussion

You can send variables to a script by way of the send( ) method of a LoadVars object. Sending data is useful when you want to record user or application events on the server. For example, when the user submits a form, you may want to send the data to a script running on a server.

The first step is to construct a new LoadVars object, as in the following example:

	var lvDataSender:LoadVars = new LoadVars();

You then need to define values for custom properties of the object. Each property ought to have the name of the variable you want to send to the script. For example, the following code defines two custom properties for lvDataSender and assigns the values from two text input components called ctiCity and ctiState:

	lvDataSender.city = ctiCity.text;
	lvDataSender.state = ctiState.text;

When you’ve defined the custom properties, call the send( ) method. The send( ) method requires at least two parameters, specifying the URL of the resource to which you want to send the data (generally a script on a server) and the name of the window in which to open the response. The window name parameter is the name of an existing window, the name of ...

Get Flash 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.