Using Flash Remoting with ColdFusion


Macromedia Flash Remoting allows you to use ColdFusion MX functionality in your Macromedia Flash movies using familiar Macromedia Flash syntax and objects.

To integrate Flash Remoting with ColdFusion Components, you need to perform the following steps:

  1. Open the data source and register it in ColdFusion MX Administrator.

  2. Install Flash Remoting Components, which allows Flash to communicate with ColdFusion and vice versa.

  3. Create the ColdFusion Component. CFCs are collections of functions called methods. You can use a CFC to query the database you're using and display the data in Flash.

  4. Connect to Flash Remoting Services and populate the Flash interface with data.

  5. Test your application. You should publish the Flash movie and watch how the simple Flash interface brings in data from the database via the CFC.

When developing ColdFusion pages for use with Flash Remoting MX, you need to do the following:

  1. Determine the Flash service name for the ColdFusion page.

  2. Pass parameters back and forth between the Flash application and the ColdFusion page.

  3. Return information to a Flash application from a ColdFusion page.

Determining the Flash Service Name

When you create a ColdFusion page that needs to be called from Flash applications, the directory name on the server containing the ColdFusion page translates to the service name. This service name is called in ActionScript from Flash.

For example, suppose you create a ColdFusion page named helloColdFusion.cfm in the directory helloExamples under your Web root (web_root/helloExamples). To call this page from a Flash application, use the following ActionScript:

 #include "NetServices.as" NetServices.setDefaultGatewayUrl("http://localhost/flashservices/gateway"); gatewayConnection =NetServices.createGatewayConnection(); CFMService =gatewayConnection.getService("helloExamples ",this); CFMService.helloColdFusion(); 

To specify subdirectories of the Web root directory or a virtual directory, use package dot notation. If the ColdFusion page, helloColdFusion.cfm, is in the directory web_root/helloExamples/ColdFusion, you can use the following ActionScript to create the service:

 CFMService =gatewayConnection.getService("helloExamples .ColdFusion ",this); 

Using the Flash Scope

ColdFusion MX defines a scope called Flash that you use to access parameters passed from Flash applications and return values to Flash applications. The Flash scope has several predefined variables that you can use to pass information.

When you call a ColdFusion page from a Flash application, the Flash Remoting gateway converts ActionScript datatypes to ColdFusion datatypes.

Here are some of the predefined variables in the Flash scope:

  • Flash.Params. Stores the array containing the parameters passed from the Flash application to the ColdFusion page. If you don't pass any parameters, Flash.Params still exists, but it's empty.

  • Flash.Result. Returns results to the Flash application from the ColdFusion page.

  • Flash.Pagesize. Returns the number of records in each increment of a recordset to Flash from a ColdFusion page.

Note

You shouldn't return a Boolean literal to Flash from ColdFusion, because ActionScript performs automatic type conversion. If you still need to return a Boolean literal, return 1 to indicate true and 0 to indicate false.

In your ColdFusion page, you access the parameter using Flash.Params, as shown in the following example:

 <CFQUERY name="flashQuery"datasource="example">     SELECT ItemName,ItemDescription,ItemCost     FROM tablItems     WHERE ItemName='#Flash.Params [1 ]#' </CFQUERY> <CFSET Flash.Result=flashQuery> 

Calling Web Services from Flash Remoting MX

Using Flash Remoting MX with ColdFusion, you can interact with Web services directly from your Flash applications without having to build a ColdFusion page or component. You can then write the code to reference a Web service in your Flash application.

Web services are remote applications that expose their functions and associated parameters using the Web Services Description Language (WSDL). WSDL files describe the functionality of a Web service, including available functions, parameters, and results. You use a Simple Object Access Protocol (SOAP) proxy to parse the WSDL and make the remote service functions available in your application. For further details about ColdFusion components and Web services, refer to Chapter 17, "Introduction to ColdFusion Components."

Securing Access to ColdFusion from Flash Remoting MX

You can control access to ColdFusion files from Flash using the ColdFusion security mechanism in the same way you control access to any ColdFusion page. This allows you to grant Flash application access to selected ColdFusion code only. Securing ColdFusion MX applications is discussed in detail in Chapter 6, "Implementing Security in ColdFusion Applications."

ColdFusion security is based on a username and password. Flash Remoting applications can pass the username and password information using the setCredentials function in ActionScript. From within your ColdFusion Application.cfm page, you can use the <CFLOGIN> tag to access the username and password information.

The following example passes a username and password to ColdFusion:

 if (inited ==null) { inited =true; NetServices.setDefaultGatewayUrl("http://localhost/flashservices/gateway"); gatewayConnection =NetServices.createGatewayConnection(); gatewayConnection.setCredentials("uname","passwd12"); myService =gatewayConnection.getService("securityTest.thecfc", this); 




Macromedia ColdFusion MX. Professional Projects
ColdFusion MX Professional Projects
ISBN: 1592000126
EAN: 2147483647
Year: 2002
Pages: 200

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net