When you use Flash Remoting MX you can use either of the following patterns for handling XML data:
Your decision as to which method to use should depend on whether it is preferable in your environment to do more processing in the server or in the client Flash application. For example, many application servers, such as ColdFusion, provide tools that are specifically optimized for XML manipulation. Therefore, although Flash includes support for XML objects and provides methods for manipulating them, you might find it more efficient to process complex XML on your server and send the processed data to Flash in custom objects, rather than having your service functions return XML to Flash. However, if you are using Flash Remoting MX to call a service that returns XML, you can use the Flash XML methods to access the XML directly.
If you do use XML objects in your Flash application, Flash Remoting MX converts between the Flash XML objects used on the client and the standard XML document object type for the application server: System.Xml.XmlDocument in .NET environments, org.w3c.dom.Document in Java, and XML document objects in ColdFusion.
The following example sends the contents of two input boxes in an XML object. The first XML element has the contents of the first text input; this element has a single child that has the contents of the second text box. The server echoes the XML back to the Flash application, and the testDocument_result result handler concatenates the contents of the two nodes to create a single string for the output box.
//Function that runs when the user clicks a "Run XML" button after entering text in
//two text boxes
function testDocument()
{
//Create the XML document.
xmlDocument = new XML();
firstElement = xmlDocument.createElement("TEST");
firstElement.attributes.message = input1.text;
secondElement = xmlDocument.createElement("INSIDETEST");
secondElement.attributes.message = input2.text;
firstElement.appendChild(secondElement);
xmlDocument.appendChild(firstElement);
//Call the service function and pass it the XML document
flashtestService.testDocument(xmlDocument);
}
//Result Handler callback function to handle the results returned by Flash Remoting
function testDocument_Result(result)
{
// result is an XML object
// for this example, get an attribute from the first node
output.text = result.firstChild.attributes["message"] + result.firstChild.firstChild.attributes["message"];
}
Note: Because the Flash XML object is a standard Flash object and not part of Flash Remoting MX, this document does not cover the details of using XML objects in Flash. For more information on using the Flash XML objects, see the Flash online Help.
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flashremoting/mx/Using_Flash_Remoting_MX/UseASData7.htm