Communication between flash and. Net (2): Application of XML objects
Introduction:
This test mainly uses the XML Object of actionscr ī Pt. The flash client sends XML (<sendinfo> <value> ABC </value> </sendinfo>) to the server (Asp.. Net), the server converts the <value> character value to uppercase and sends it back to the Flash client in XML format (<replayinfo value = 'value'/>.
Key knowledge points:
For details, see the Flash MX Professional 2004 help document.
1. xml. sendandload (URL, targetxmlobject
Encode the specified XML object as an XML document and send it to the specified URL using the POST method. Download the server response and load it to the targetxmlobject specified in the parameter. The server response is loaded in the same way as the load () method.
2. xml. onload ()
Flash Player calls the XML file from the server. If the XML document is successfully received, the success parameter is true. If this document is not received, or an error occurs when receiving responses from the server, the success parameter is false.
CodeAnd description:
Actionscr platinum PT: Stop ();
VaR strxml = "<sendinfo> <value> ABC </value> </sendinfo> ";
VaR sendxml: xml = New XML (); // defines the XML Object sent to the server
Sendxml. ignorewhite = true; // when true, the white space is ignored.
Sendxml. parsexml (strxml); // interpret the XML string as an object
VaR rexml: xml = New XML (); // defines the XML Object of the information returned by the receiving server.
Rexml. ignorewhite = true;
Rexml. onload = getreplayinfo; // defines the call to the "getreplayinfo" function when the load and sendandload Methods load data.
Sendxml. sendandload ("your url", rexml );
Trace ("server processing ...");
Function getreplayinfo ()
{
VaR getxml: xml = New XML ();
Getxml. ignorewhite = true;
Getxml. parsexml (this );
If (getxml. firstchild. nodename = "replayinfo ")
{
Trace (getxml. firstchild. Attributes. value );
}
Else
{
Trace ("server error! ");
}
} ASP. NET Protected void page_load (Object sender, eventargs E)
{
Stream xmlstream = request. inputstream;
Dataset DS = new dataset ();
DS. readxml (xmlstream );
Xmldocument xmldoc = new xmldocument ();
Xmldoc. loadxml (Ds. getxml ());
String value = xmldoc. selectsinglenode ("sendinfo"). childnodes [0]. innertext; // value of node <value>
Value = value. toupper (); // converts the value to uppercase.
Response. Write ("<replayinfo value = '" + value + "'/> ");
// Send back to the client flash
}
Note: The following information (marked in red) should be added to the HTML page declaration of ASP. NET to ensure that the page correctly receives XML data streams.
<% @ Page Language = "C #" Validaterequest = "false" Autoeventwireup = "true" codefile = "xmltest. aspx. cs" inherits = "xml_xmltest" %> Test results: Processing the server...
ABC
posting