View comments | RSS feed

sendAndLoad (XML.sendAndLoad method)

public sendAndLoad(url:String, resultXML:XML) : Void

Encodes the specified XML object into an XML document, sends it to the specified URL using the POST method, downloads the server's response, and loads it into the resultXMLobject specified in the parameters. The server response loads in the same manner used by the XML.load() method.

When the sendAndLoad() method is executed, the XML object property loaded is set to false. When the XML data finishes downloading, the loaded property is set to true if the data successfully loaded, and the onLoad event handler is invoked. The XML data is not parsed until it is completely downloaded. If the XML object previously contained any XML trees, those trees are discarded.

When using this method, consider the Flash Player security model:

For Flash Player 8:

For more information, see the following:

For Flash Player 7 and later websites can permit cross-domain access to a resource via a cross-domain policy file. In SWF files of any version running in Flash Player 7 and later, the url parameter must be in exactly the same domain. For example, a SWF file at www.someDomain.com can load data only from sources that are also at www.someDomain.com.

In SWF files running in a version of the player earlier than Flash Player 7, the url parameter must be in the same superdomain as the SWF file that is issuing this call. A superdomain is derived by removing the left-most component of a file's URL. For example, a SWF file at www.someDomain.com can load data from sources at store.someDomain.com, because both files are in the same superdomain of someDomain.com.

Availability: ActionScript 1.0; Flash Player 5 - Behavior changed in Flash Player 7.

Parameters

url:String - A string; the destination URL for the specified XML object. If the SWF file issuing this call is running in a web browser, url must be in the same domain as the SWF file; for details, see the Description section.

resultXML:XML - A target XML object created with the XML constructor method that will receive the return information from the server.

Example

The following example includes ActionScript for a simple e-commerce storefront application. The XML.sendAndLoad() method transmits an XML element that contains the user's name and password, and uses an onLoad handler to process the reply from the server.

var login_str:String = "<login username=\""+username_txt.text+"\" password=\""+password_txt.text+"\" />";
var my_xml:XML = new XML(login_str);
var myLoginReply_xml:XML = new XML();
myLoginReply_xml.ignoreWhite = true;
myLoginReply_xml.onLoad = myOnLoad;
my_xml.sendAndLoad("http://www.flash-mx.com/mm/login_xml.cfm", myLoginReply_xml);
function myOnLoad(success:Boolean) {
    if (success) {
        if ((myLoginReply_xml.firstChild.nodeName == "packet") &&
            (myLoginReply_xml.firstChild.attributes.success == "true")) {
            gotoAndStop("loggedIn");
        } else {
            gotoAndStop("loginFailed");
        }
    } else {
        gotoAndStop("connectionFailed");
    }
}

See also

send (XML.send method), load (XML.load method), loaded (XML.loaded property), onLoad (XML.onLoad handler)


Version 8

Comments


No screen name said on Mar 12, 2006 at 9:00 PM :
After having XML.sendAndLoad fail silently repeatedly since moving my authoring environment to Flash 8, I finally got it to work correctly by adding the following line of code reight before the sendAndLoad:

myXML_data.contentType = "text/xml";

Havent been able to find any info at all on this, but in my IDE, LoadVars and XML wil NOT execute a sendAndLoad without this line. Verified when published all the way back to 6.

I'm on xp, behavior is browser independent.
RichClient said on Apr 22, 2006 at 9:00 PM :
I made the above comment, but eventually noticed that I was probably wrong.
Somewhere along the line, I had changed the name of the return target object. This parameter of sendAndLoad can be the object itself of course, but if using another object make sure its named exactly or it will fail silently.

Not sure about the doc type thing, but it does help servers correctly identify the data stream in some server setups.
mstatkus said on Jan 5, 2007 at 3:21 PM :
I've made attempts using PHP successful, however I'm having issues with this method against ASP.NET.
As a test I tried xml.sendAndLoad against a XML file sitting on a server and it fails to. Is sendAndLoad expecting some type of raw response?
No screen name said on Jan 18, 2007 at 12:57 PM :
To retrieve the POST date use the following

** ASP.Net not sure if it works have not tried it out yet
Request.BinaryRead(Request.TotalBytes)

** PHP I know this works
file_get_contents("php://input");

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002879.html