The
onLoginReply()
script, read the commented lines.)
function onLoginReply() {
// Get the first XML element
var e = this.firstChild;
// If the first XML element is a LOGINREPLY element with
// status OK, go to the portfolio screen. Otherwise,
// go to the login failure screen and let the user try again.
if (e.nodeName == "LOGINREPLY" && e.attributes.status == "OK") {
// Save the session ID for future communications with server
sessionID = e.attributes.session;
// Go to the portfolio viewing screen
gotoAndStop("portfolioView");
} else {
// Login failed!
gotoAndStop("loginFailed");
}
}
The first line of this function,
XML object
loginReplyXML
because
this
onLoginReply()
onLoginReply()
loginReplyXML
To send the user name and password as XML to the server and to load an XML response back
into the SWF file, you can use the
// C. Send the LOGIN element to the server,
//
place the reply in loginReplyXML
loginXML.sendAndLoad("https://www.imexstocks.com/main.cgi", loginReplyXML);
Note: This design is only an example, and Macromedia can make no claims about the level of security
it provides. If you are implementing a secure password-protected system, make sure you have a good
understanding of network security.
For more information, see "Integrating XML and Flash in a Web Application" at
www.macromedia.com/support/flash/interactivity/xml/
"ActionScript Dictionary," on page
Using the XMLSocket class
ActionScript provides a built-in XMLSocket class that allows you to open a continuous
connection with a server. A socket connection allows the server to publish (or "push")
information to the client as soon as that information is available. Without a continuous
connection, the server must wait for an HTTP request. This open connection removes latency
issues and is commonly used for real-time applications such as chats. The data is sent over the
socket connection as one string and should be in XML format. You can use the XML class to
structure the data.
To create a socket connection, you must create a server-side application to wait for the socket
connection request and send a response to the SWF file. This type of server-side application can
be written in a programming language such as Java.
184
Chapter 10: Working with External Data
function is defined in the first frame of the SWF file. (To understand this
Go to the login failure screen.
var e = this.firstChild
that has just been loaded with XML from the server. You can use
has been invoked as
appears to be a normal function, it actually behaves as a method of
.
sendAndLoad()
205.
, uses the keyword
loginReplyXML.onLoad
method, as shown here:
and the
XML class
to refer to the
this
, so even though
entry in
Chapter 12,
Need help?
Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?