|
Sending the LOGIN XML element
The user interface for the online brokerage system is a Flash movie. The first frame of the Flash movie contains a prompt for a user name and password. This frame contains two text fields assigned the variables username and password to input the user name and password. There is also a button labeled "Enter", and perhaps another button labeled "Forgot your password?" for the benefit of absent-minded users. The Enter button has the following actions assigned to it:
on (release) {
// A. Construct a XML document with a LOGIN element
loginXML = new XML();
loginElement = loginXML.createElement("LOGIN");
loginElement.attributes.username = username;
loginElement.attributes.password = password;
loginXML.appendChild(loginElement);
// B. Construct a XML object to hold the server's reply
loginReplyXML = new XML();
loginReplyXML.onLoad = onLoginReply;
// C. Send the LOGIN element to the server,
//place the reply in loginReplyXML
loginXML.sendAndLoad("https://www.imexstocks.com/main.cgi",
loginReplyXML);
}
Part (A) of this script constructs a LOGIN XML element as described in the above section. A blank LOGIN element is created, and then its user name and password attributes are filled in. Finally, the newly created LOGIN element is inserted into the XML document.
Part (B) creates a blank XML object that will receive the LOGINREPLY XML element from the server. The LOGINREPLY element will arrive asynchronously, much like the data from a loadVariables action. When the data arrives, the onLoad method of the XML object will be invoked. You supply your own onLoad handler which you define in the onLoginReply function. You attach the handler to the loginReplyXML object by setting its onLoad property to refer to the onLoginReply function. This function will process the LOGINREPLY element when it arrives.
Part (C) transmits the LOGIN XML element to the server. The XML.sendAndLoad method sends XML to the server using the HTTP/HTTPS protocol, and places the server's response in the XML object specified in the second argument, in this case loginReplyXML . Note that the response arrives asynchronously, so sendAndLoad will return immediately even if the server has not yet responded. When the response does arrive, loginReplyXML.onLoad will be invoked.
|