User Guide
Sending and loading variables to and from a remote source 281
The following XML class methods send and load XML data to a server by using the HTTP
POST method:
• The load() method downloads XML from a URL and places it in an ActionScript
XML object.
• The send()method encodes the XML object into an XML document and sends it to a
specified URL using the
POST method. If specified, a browser window displays returned data.
• The sendAndLoad() method sends an XML object to a URL. Any returned information is
placed in an ActionScript XML object.
For example, you could create a brokerage system that stores all its information (user names,
passwords, session IDs, portfolio holdings, and transaction information) in a database.
The server-side script that passes information between Flash and the database reads and writes the
data in XML format. You can use ActionScript to convert information collected in the SWF file
(for example, a user name and password) to an XML object and then send the data to the server-
side script as an XML document. You can also use ActionScript to load the XML document that
the server returns into an XML object to be used in the SWF file.
The flow and conversion of data between a SWF file, a server-side script, and a database
The password validation for the brokerage system requires two scripts: a function defined on
Frame 1, and a script that creates and then sends the XML objects created in the document.
When a user enters information into text fields in the SWF file with the variables
username and
password, the variables must be converted to XML before being passed to the server. The first
section of the script loads the variables into a newly created XML object called
loginXML. When
a user clicks a button to log in, the
loginXML object is converted to a string of XML and
sent to the server.
The following ActionScript is placed on the Timeline and is used to send XML-formatted data to
the server. To understand this script, read the commented lines (indicated by the characters
//):
//ignore XML white space
XML.prototype.ignoreWhite = true;
// Construct an XML object to hold the server's reply
var loginReplyXML:XML = new XML();
// this function triggers when an XML packet is received from the server.
loginReplyXML.onLoad = function(success:Boolean) {
if (success) {
XML document
username
XML document
Response
SQL request
password
Submit
loginReplyXML
Flash application
Database
Jean Smith
loginXML