Table of Contents

LoadVars.send( ) Method Flash 6

transfer URL-encoded variables to a server-side application or script
loadVarsObject.send(url, target)
loadVarsObject.send(url, target, method)

Arguments

url

A string specifying the absolute or relative location of the external script or application that receives the variables.

target

A string specifying the name of the browser window or frame into which to load results. Can be a custom name or one of the four presets: "_blank", "_parent", "_self", or "_top".

method

An optional string specifying the HTTP method by which to send the properties of loadVarsObject to an external script—either "GET" or "POST". If omitted, it defaults to "POST". The Standalone Flash Player for Windows always uses the "GET" method, regardless of the method specified. See Appendix F for details on support for GET and POST.

Returns

A Boolean indicating whether the method executed successfully. Note that the return value is less useful than it appears. When passed any value for url (including undefined!), send( ) returns true. When invoked with no arguments, send( ) returns false.

Description

The send( ) method converts all properties of loadVarsObject to a string of URL-encoded variables, which it then sends to url in an HTTP request, using the method specified by method. If the script or application at url outputs a result, it is displayed in the browser frame or window specified by target. If the movie is running in the Standalone Player, the system's default browser is launched. See the global getURL( ) function for a detailed explanation of the target and method parameters. For an explanation of URL encoding, see the Description heading of the LoadVars class. The URL-encoded string sent to url can be viewed locally via the LoadVars.toString( ) method.

Note that the getURL( ) function also can pass variables to a remote script, but it is less convenient than LoadVars.send( ) because it requires the use of a movie clip to hold the variables.

Bugs

Macromedia's documentation states that when the target parameter is not specified, the script at url is executed, but the results are discarded. However, in Flash Player 6, tests show that when target is not specified, the send( ) the method fails to execute the script at url.

Example

The following code uses a LoadVars object to send the properties name and age as URL-encoded variables to the script userFind.pl:

// Create the LoadVars object
varSender = new LoadVars();
   
// Assign properties to the varSender object
// These are the variables sent to the server
varSender.name = "Bruce";
varSender.age = "13";
   
// Send variables to server, and catch reply in a new browser window
varSender.send("http://www.someserver.com/cgi-bin/userFind.pl", "_blank", "GET");

See Also

getURL( ), LoadVars.onLoad( ), LoadVars.sendAndLoad( ), LoadVars.toString( )


Table of Contents