You can test this code by using a user name of
first section of the script generates the following XML when the user clicks the login button:
<login username="JeanSmith" password="VerySecret" />
The server receives the XML, generates an XML response and sends it back to the SWF file. If the
password is accepted, the server responds with the following:
<loginreply status="OK" session="46597865D0B7884E007DEA7D" />
This XML includes a
which will be used in all communications between the client and server for the rest of the session.
If the password is rejected, the server responds with the following message:
<loginreply status="FAILURE" />
The
XML node must load into a blank XML object in the SWF file. The following
loginreply
statement creates the XML object
// Construct an XML object to hold the server's reply
var loginReplyXML:XML = new XML();
loginReplyXML.onLoad = function(success:Boolean) {
The second statement in this ActionScript defines an anonymous (inline) function, which is
called when the
onLoad
The login button (
login_btn
the server and to load an XML response back into the SWF file. You can use the
method to do this, as shown in the following example:
loginXML.sendAndLoad("http://www.flash-mx.com.com/mm/main.cfm",
loginReplyXML);
First, the XML-formatted data is created, using the values that the user inputs in the SWF file,
and that XML object is sent using the
function, the
loadVariables()
doesn't wait for results before being returned) and loads into the
the data arrives, the
onLoad
function, which is called when the
loginReplyXML
element.
loginreply
Note: This function must always be on the frame that contains the ActionScript for the login button.
If the login is successful, the SWF file progresses to the
successful, then the playhead moves to the
condition and case statement. For more information on case and break statements, see
in Flash ActionScript Language Reference. For more information on conditions, see
break
in Flash ActionScript Language Reference.
else
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 Language Reference.
attribute that contains a unique, randomly generated session ID,
session
loginreplyXML
event triggers.
instance) is used to send the user name and password as XML to
sendAndLoad
loginreply
handler of the
loginReplyXML
loginfailure
Sending and loading variables to and from a remote source
and the password
JeanSmith
to receive the XML node:
method. Similar to data from a
XML element arrives asynchronously (that is, it
loginReplyXML
object is called. You must define the
handler triggers, so it can process the
onLoad
frame label. If the login is not
welcome
frame label. This is processed using a
and the "XML class" entry in Flash
. The
VerySecret
sendAndLoad()
object. When
and
case
and
if
283
Need help?
Do you have a question about the FLASH MX 2004-USING ACTIONSCRIPT IN FLASH and is the answer not in the manual?
Questions and answers