XML.sendAndLoad( ) Method

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
XML.sendAndLoad( ) Method Flash 5

send XML source code to an external script or application and receive XML source in return
xmlDoc.sendAndLoad(url, resultXML)

Arguments

url

A string specifying the location of a script or application to which xmlDoc should be sent.

resultXML

A reference to an XML document object that will receive the returned XML source code.

Description

The sendAndLoad( ) method serializes xmlDoc into a string of XML source code and sends that string to a script or application that resides at url. The specified xmlDoc must be the top-level node in an XML object hierarchy (i.e., an instance of the XML class, not the XMLnode class).

The receiving script or application at url is expected to process the XML in some way and send an XML document back as a response. The response document is caught by Flash, parsed, converted into an XML object hierarchy, and placed in resultXML. Any previous contents of resultXML are replaced by the newly loaded XML content. See XML.send( ) for important information about sending XML to a server. Note that unlike send( ), sendAndLoad( ) sends xmlDoc using a POST request in both the browser and Standalone versions of Flash Player 6. However, in the Standalone Flash Player 5 on Windows, sendAndLoad( ) uses the GET method. See Appendix F for details on support for GET and POST.

Usage

Before accessing content imported with sendAndLoad( ), we must be sure that the loading and parsing operations are complete. To do so, we either check the value of resultXML's loaded property or we assign resultXML an onLoad( ) event handler to respond to the load completion. See the XML.loaded and XML.onLoad( ) entries for details. To determine the result of parsing the loaded data, we check the document's status property.

XML.sendAndLoad( ) is subject to the domain-based security restrictions described under System.security.allowDomain( ).

Example

// Create an XML document. myDoc = new XML("<P>hello server!</P>");     // Create an empty XML document to receive the server's response. serverResponse = new XML();     // Send myDoc to the server, and place the response in serverResponse. myDoc.sendAndLoad("http://www.domain.com/cgi-bin/readData.cgi", serverResponse);     // Add an onLoad( ) handler to serverResponse that displays the response // from the server in the text field output. serverResponse.onLoad = function () {   output = serverResponse.toString(); }

See Also

XML.load( ), XML.loaded, XML.onData( ), XML.onLoad( ), XML.send( ), XML.status



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net