19.14. Sending XML Data and Receiving a Response


You want to send XML data to a server-side script and load the response into the same Flash movie.


Use the XML.sendAndLoad( ) method.


The sendAndLoad( ) method does just what its name suggests—it sends XML data to a server-side script and loads the response back into Flash. It is ideal when you want to send data to the server for processing and then receive the results back in the Flash movie. Additionally, since there are limitations in the XML.send( ) method, the sendAndLoad( ) method is the best choice even in situations in which you don’t expect any response from the server.

The sendAndLoad( ) method sends the XML data from the object on which it is called. You must specify a target XML object into which the response is loaded. You can use the same XML object to load the data as you use to send it, but generally it is better to create a separate XML object for the loaded data, since the loaded response replaces any existing data in the target XML object. Therefore, in most cases, you should create two XML objects—one for sending and one for loading. For example:

// Create the loading object.
myLoadXML = new XML(  );

// As when loading data using the load(  ) method, set ignoreWhite to true.
myLoadXML.ignoreWhite = true;

// Define the onLoad(  ) method. (See Recipe 19.11.) myLoadXML.onLoad = function (success) { if (success) { trace("The XML was successfully parsed. Here are the contents: "); trace(this); } ...

Get Actionscript Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.