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

  • Download
  • Add to my manuals
  • Print
  • Page
    / 40
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 13
This is the Title of the Book, eMatter Edition
Copyright © 2003 O’Reilly & Associates, Inc. All rights reserved.
12
|
Chapter 1: Introduction to Flash Remoting
<!---Query the database for matching entries--->
<cfquery name="myLogin" datasource="myDatasource">
SELECT username FROM Users
WHERE username = '#username#' and password = '#password#'
</cfquery>
<!---Check whether a match was found--->
<cfif myLogin.RecordCount LT 1>
<cfset logged = "0">
</cfif>
<!---Create an XML string to return to the Flash movie--->
<cfset returnXML = "<return username=""" & username>
<cfset returnXML = returnXML & """ logged=""" & logged & """ />">
<cfoutput>#returnXML#</cfoutput>
As you can see, the code is not intuitive—the XML is manually serialized into a
string on both client and server, and the string has to be deserialized and turned into
an XML object again on the Flash side. All of this code was created to send one sim-
ple XML object from the Flash movie to the server and back again. Imagine if this
were something more complex, such as a recordset with 10 or 15 fields and 1,000
rows.
The Flash Remoting version of the previous code might look like this:
var myURL = "http://127.0.0.1/flashservices/gateway";
var myServer = NetServices.createGatewayConnection(myURL);
var myService = myServer.getService("com.oreilly.frdg.authentication", this);
myService.getLogin(username, password);
// The result handler for the getLogin( ) method invocation
function getLogin_Result (result_rs) {
if (result_rs.getLength( ) < 1) {
greeting = "Login failed";
} else {
greeting = "Hello " + result_rs.getItemAt(0).username;
greeting += ". Login was successful";
}
}
And the server-side code might look like this:
<cfcomponent displayName="login">
<cffunction name="getLogin" returnType="query" access="remote">
<cfargument name="username" type="string">
<cfargument name="password" type="string">
<cfquery name="myLogin" datasource="myDatasource">
SELECT username FROM Users
WHERE username = '#username#' and password = '#password#'
</cfquery>
<cfreturn myLogin>
</cffunction>
</cfcomponent>
Page view 13
1 2 ... 9 10 11 12 13 14 15 16 17 18 19 ... 39 40

Comments to this Manuals

No comments