Using Flash Remoting Update



You can use Flash Remoting Update to create Rich Internet Applications by using Adobe ColdFusion with Adobe Flash Builder or earlier versions of Flex Builder, with the advanced data retrieval features of ColdFusion, such as the cfpop, cfldap, and cfquery tags. In addition, you can use Flash Remoting Update to create Flash Forms and SWF files that contain features, such as server call backs and customized user interface.

Prerequisites for using Flash Remoting Update

You can use Flash Remoting Update with all configurations of ColdFusion (server, multiserver, and J2EE) on all the platforms that ColdFusion supports.

To use Flash Remoting Update, you must have the following installed:

  • Flex 2 SDK or later, Flex Builder 2 or later, Flash Builder 4.

    Note: With ColdFusion 9, you will need to install LiveCycle Data Services 2.6.1 manually because it is not available as an option with the ColdFusion installer. However, ColdFusion 9 is available with the BLAZE DS installation, which allows messaging support. For more information about manually installing LiveCycle Data Services ES 2.6.1, see Installing LiveCycle Data Services Manually in the Installation Guide.
  • Flash Player 8.5 or later

Configure Flex Compilation

You use Flash Builder or the Flex SDK to compile Flex applications into SWF files. To use the Flash Remoting Update, these programs must use the ColdFusion services-config.xml file when compiling the MXML.

You need to configure Flash Builder to use the ColdFusion configuration file, or specify the file when you use the SDK to compile your application (as described in Compile and Run the application).

Configure Flex Builder 2 to use the ColdFusion configuration file

When you use the Flex Builder Project Setup Wizard and select ColdFusion as the server type, the wizard configures Flex Builder to use the services-config.xml file for you. Use the following steps to configure your project:

  1. Select File> New> Flex Project to open the New Flex Project Wizard. and enter the appropriate information in the first sections of the Create a Flex project page.

  2. Select one of the radio buttons, as follows:

    • Select ColdFusion Flash Remoting to compile in Flex Builder.

    • If you installed LiveCycle Data Services with ColdFusion and want to use messaging or data management, select Flex Data Services.

  3. If you select Flex Data services, select whether to compile the application locally in Flex Builder or on the application server where the page is viewed. Do not select to compile code that you deploy on the server; this option is for development purposes only.

  4. Click Next and complete creating the project, then click Finish.

If you select Basic on the first Create a Flex Project page, and decide later to compile the application for use with ColdFusion, configure Flex Builder manually, as follows:

  1. Select Project > Properties.

  2. Select Flex Complier in the right pane of the Properties dialog.

  3. In the Additional Compiler arguments add -services= followed by the absolute path to the services-config.xml file in the local ColdFusion installation. For example, on a Windows system with a default ColdFusion stand-alone installation, specify the following argument string.

    -services=C:/ColdFusion9/wwwroot/WEB-INF/flex/services-config.xml

Configure Flex Builder 3 to use the ColdFusion configuration file

When you use the Flex Builder Project Setup Wizard and select ColdFusion as the server type, the wizard configures Flex Builder to use the services-config.xml file for you. Use the following steps to configure your project:

  1. Select File> New> Flex Project to open the New Flex Project Wizard. and enter the appropriate information in the first sections of the Create a Flex project page.

  2. In the Server technology section of the Create a Flex project page, select ColdFusion as the Application server type, and select Use remote object access service.

  3. Select one of the radio buttons, as follows:

    • Select ColdFusion Flash Remoting to compile in Flex Builder.

    • If you installed LiveCycle Data Services and want to compile the application on the server, select LiveCycle Data services in Flex Builder 3.

  4. Click Next to open the Configure ColdFusion page, and enter the required information. If you selected LiveCycle Data services in step 3, you can select to compile the application locally or on the server. Select to compile on the server only when you are developing your application, for convenience. Do not select to compile on the server code that you deploy, because the MXML page is not compiled to a SWF file until the user requests it, and the compiler does not create an HTML wrapper page.

  5. Click Finish to complete the configuration.

If you do not specify ColdFusion in the Server technology section of the Create a Flex project page, and decide later to compile the application for use with ColdFusion, configure Flex Builder manually, as follows:

  1. Select Project > Properties.

  2. Select Flex Complier in the right pane of the Properties dialog.

  3. In the Additional Compiler arguments add -services= followed by the absolute path to the services-config.xml file in the local ColdFusion installation. For example, on a Windows system with a default ColdFusion stand-alone installation, specify the following argument string.

    -services=C:/ColdFusion8/wwwroot/WEB-INF/flex/services-config.xml

Specify a CFC

To specify a CFC to connect to, you do one of the following:

  • Specify the dot-delimited path from the web root to the CFC in the MXML.

  • Create a named resource for the CFC. Creating this resource is like registering a data source; you then use the resource name in your XML.

Specify the CFC in the MXML

To specify the CFC in your MXML, use code such as the following:

<mx:RemotObject 
    id="myCfc" 
    destination="ColdFusion" 
    source="myApplication.components.User"/>

ColdFusion 9 supports BlazeDS that allows messaging support for ColdFusion. When you install ColdFusion, the following files are added to the /WEB-INF/flex directory:

  • remoting-config.xml

  • messaging-config.xml

  • services-config.xml

  • proxy-config.xml

The destination ColdFusion is preconfigured in remoting-config.xml. The default source value for this destination is the wildcard, *. For more information about the changes in Flash Remoting for ColdFusion 9, see Changes in the XML configuration files for Flash Remoting in ColdFusion 9.

You do not have to use the ColdFusion destination if you have configured other valid destinations in the configuration file. In this case, the destination definition must specify * as the value of its source element. If you specify a source other than * in remoting-config.xml, then that source definition overrides the source specified in the MXML.

For details of defining a destination, see Create a named resource for a CFC.

Create a named resource for a CFC

  1. Edit the WEB-INF/flex/remoting-config.xml file by adding a destination entry for the CFC, for example:

    <service id="remoting-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage"> 
        <adapters> 
        <adapter-definition id="cf-object"      
        class="coldfusion.flash.messaging.ColdFusionAdapter" default="true" /> 
        <adapter-definition id="java-object" 
        class="flex.messaging.services.remoting.adapters.JavaAdapter" /> 
        </adapters> 
     
            <default-channels> 
            <channel ref="my-cfamf" /> 
            </default-channels> 
                <destination id="ColdFusion"> 
            <channels> 
     
            <channel ref="my-cfamf" /> 
            </channels> 
            <properties> 
            <source>*</source> 
            </properties> 
        </destination> 
    </service> 

    The source attribute specifies the dot notation to the CFC from the web root (the classpath to the CFC).

    The channel-ref tag refers to the channel-definition in the services-config.xml file. In the preceding sample, the my-cfamf channel-definition has been referenced, which looks similar to the following:

    <channel-definition id="my-cfamf" class="mx.messaging.channels.AMFChannel"> <endpoint uri="http://{server.name}:{server.port}{context.root}/flex2gateway/" class="coldfusion.flash.messaging.CFAMFEndPoint" /> 
        <properties> 
            <polling-enabled>false</polling-enabled> 
            <serialization> 
                <enable-small-messages>false</enable-small-messages> 
            </serialization> 
            <coldfusion> 
                <access> 
                    <use-mappings>true</use-mappings> 
                    <method-access-level>remote</method-access-level> 
                </access> 
                <use-accessors>true</use-accessors> 
                <use-implicit-accessors>false</use-implicit-accessors> 
                <use-structs>false</use-structs> 
                <property-case> 
                    <force-cfc-lowercase>false</force-cfc-lowercase> 
                    <force-query-lowercase>false</force-query-lowercase> 
                    <force-struct-lowercase>false</force-struct-lowercase> 
                </property-case> 
            </coldfusion> 
        </properties> 
    </channel-definition>
  2. Restart the ColdFusion server.

The following table describes the XML attributes for remoting-config.xml:

Element

Description

destination id

The destination attribute that the MXML mx:RemoteObject tag must specify to access the CFC.

channels

A container for one of more child channel attributes specifying the AMF channels to use to access the ColdFusion server.

channel-ref

Reference to the channel-definition id specified in the services-config.xml file.

source

The dot-delimited file path to the CFC, from the cfWebRoot, or, if the use-mappings property is true, an entry in the ColdFusion Administrator Mappings page.

access

Properties that control how the CFC is accessed on the ColdFusion server.

The following table lists the XML attributes for services-config.xml:

Elements

Description

channel-definition id

Channel definition

coldfusion

Contains tags to set access levels, mappings to find CFCs, access to public or remote methods.

access

define the resolution rules and access level of the CFC being invoked

use-mappings

Use the ColdFusion mappings to find CFCs, by default only CFC files under your web root can be found.

method-access-level

Allow "public and remote" or just "remote" methods to be invoked

use-accessors

Whether the Value Object CFC has getters and setters. Set the value of use-accessors to true if there are getters and setters in the Value Object CFC.

use-implicit-accessors

Whether the Value Object CFC has implicit getters and setters. Set the value of use-implicit-accessors to true if there are implicit getters and setters in the Value Object CFC.

Note: This flag needs to be set to true only if you are using a non-persistent CFC.

use-structs

Set the value of use-structs to true if you don't require any translation of ActionScript to CFCs. The assembler can still return structures to Flex, even if the value is false. The default value is false.

force-cfc-lowercase
force-query-lowercase
force-struct-lowercase 

Whether to make property names, query column names, and structure keys lowercase when converting to ActionScript. Query column names must precisely match the case of the corresponding ActionScript variables. The default value is false.

Use the CFC

Use the CFC in your application:

  1. In the MXML file, you use the <mx:RemoteObject> tag to connect to your CFC named resource. With this connection, you can call any remote method on the CFC.

  2. If you created a destination for the CFC in the remoting-config.xml file, specify the destination name in the mx:RemoteObject tag; for example:

    <mx:RemoteObject  
        id="a_named_reference_to_use_in_mxml"  
        destination="CustomID"  
        result="my_CFC_handler(event)"/> 

    If you did not create a destination for the CFC, specify the ColdFusion destination and the CFC path in the mx:RemoteObbject tag; for example:

    <mx:RemotObject 
        id="myCfc" 
        destination="ColdFusion" 
        source="myApplication.components.User"/>
  3. Call a CFC method, for example, as the following example shows:

    <mx:Button label="reload" click="my_CFC.getUsers()"/> 

    In this example, when a user presses a button, the Click event calls the CFC method getUsers.

  4. Specify a handler for the returned result of the CFC method call for the <mx:RemoteObject> tag, as the following example shows.

    private function my_CFC_handler( event:ResultEvent ) 
    { 
    // Show alert with the value that is returned from the CFC. 
    mx.controls.Alert.show(ObjectUtil.toString(event.result)); 
    }

Compile and Run the application

You can compile and run your application from Flash Builder or without using Flash Builder. The techniques you can use also depend on whether you have installed LiveCycle Data Services.

Compile and run the application using Flash Builder

To compile and run an application using Flash Builder, make sure that Flash Builder is configured as described in Configure Flex Compilation. Compile your application normally to create a SWF file. When you configure your Flash Builder project you can specify the location in which to place it. By default, Flash Builder attempts to place the SWF file and an HTML wrapper page under the web root. You can then run the application as appropriate, for example, by requesting the HTML wrapper for the SWF file in a browser.

Compile and Run the application without Flash Builder

To compile the application directly using the SDK, set the Flex compiler to use the ColdFusion services-config.xml file. Set the Flex compiler by adding to the mxml command line “ -services=” followed by the absolute path to the services-config.xml file in the local ColdFusion installation. For example, on a Windows system with a default ColdFusion standalone installation, specify the following argument string.

-services=C:/ColdFusionCentuar/wwwroot/WEB-INF/flex/services-config.xml