EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 656

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
656 Working with External Data
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) {
// (optional) Create two text fields for status/debugging
// status_txt.text = this.firstChild.attributes.status;
// debug_txt.text = this.firstChild;
switch (this.firstChild.attributes.STATUS) {
case 'OK' :
_global.session = this.firstChild.attributes.SESSION;
trace(_global.session);
gotoAndStop("welcome");
break;
case 'FAILURE' :
gotoAndStop("loginfailure");
break;
default :
// this should never happen
trace("Unexpected value received for STATUS.");
}
} else {
trace("an error occurred.");
}
};
// this function triggers when the login_btn is clicked
login_btn.onRelease = function() {
var loginXML:XML = new XML();
// create XML formatted data to send to the server
var loginElement:XMLNode = loginXML.createElement("login");
loginElement.attributes.username = username_txt.text;
loginElement.attributes.password = password_txt.text;
loginXML.appendChild(loginElement);
// send the XML formatted data to the server

Table of Contents

Related product manuals