MACROMEDIA FLASH REMOTING MX-USING FLASH REMOTING FOR FLASH MX 2004 ACTIONSCRIPT 2.0 Specifications Page 13

  • Download
  • Add to my manuals
  • Print
  • Page
    / 40
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 12
This is the Title of the Book, eMatter Edition
Copyright © 2003 O’Reilly & Associates, Inc. All rights reserved.
Benefits
|
11
In a typical scenario involving an XML object being sent from a Flash 5 movie to a
ColdFusion page, the Flash movie first has to create the XML string manually. Then
it has to send the XML string to the ColdFusion page, which has to parse the XML
before being able to utilize it. In addition, the server has to transform the result of
any operation on the server back into XML to send the result to the Flash movie. The
Flash movie then has to parse this XML once again to use the returned information.
All of this parsing of data eats up valuable resources and bandwidth even before the
application logic can be utilized.
In other words, a Flash 5 movie can’t use the data directly from the application
server, and the application server can’t use the data directly from Flash 5.
Take a typical example of a username and password login. The ActionScript for the
Flash movie could create a simple XML string and pass it to the ColdFusion page:
// Set up a new XML object.
var returnXML = new XML( );
returnXML.ignoreWhite = true;
// Set the callback function for the response from the server.
returnXML.onLoad = handleReply;
// Create an XML string.
// Form field variables are replaced in the string.
var my_xml = '<?xml version="1.0" encoding="iso-8859-1"?>';
my_xml += '<myValidation>';
my_xml += '<username>' + username + '</username>';
my_xml += '<password>' + password + '</password>';
my_xml += '</myValidation>';
var flash_xml_object = new XML(my_xml)
// Send it to the server and then load it into the my_xml object.
flash_xml_object.sendAndLoad("http://192.168.0.4/myLogin.cfm", returnXML);
function handleReply (result) {
if (result) {
if (this.firstChild.attributes.logged == "1") {
greeting = "Hello " + this.firstChild.attributes.username;
greeting += ". Login was successful";
} else {
greeting = "Login failed";
}
} else {
greeting = "There was a communication failure.";
}
}
A ColdFusion page to handle the logic would look like this:
<!---Deserialize the username and password from the XML--->
<cfset logged="1">
<cfset my_xml = XMLParse(URLDecode(GetHttpRequestData( ).content))>
<cfset username = my_xml.myValidation.username.xmltext>
<cfset password = my_xml.myValidation.password.xmltext>
Page view 12
1 2 ... 8 9 10 11 12 13 14 15 16 17 18 ... 39 40

Comments to this Manuals

No comments