Share this Page URL

Chapter 26. Integrating with Macromedia ... > Calling CFC Methods from Flash - Pg. 871

Integrating with Macromedia Flash Listing 26.8. MerchDetailProvider.cfm--Providing Details About the Selected Product <!--- Filename: MerchDetailProvider.cfm Author: Nate Weiss (NMW) Purpose: Provides film detail to a Flash movie ---> <!--- We are expecting a MerchID parameter to be passed from Flash ---> <cfparam name="FLASH.merchID" type="numeric"> <!--- Query the database for merchandise records ---> <cfquery name="MerchQuery" datasource="#APPLICATION.dataSource#" maxrows="1"> SELECT MerchID, MerchName, MerchDescription, ImageNameSmall, MerchPrice FROM Merchandise WHERE MerchID = #FLASH.merchID# </cfquery> <!--- Format the MerchPrice column in the appropriate currency format ---> <!--- (It's easier to do this with ColdFusion than with ActionScript) ---> <cfset merchQuery.merchPrice = lsCurrencyFormat(merchQuery.MerchPrice)> <!--- This will be available as the "result" variable in the ---> <!--- MerchDetailProvider_Result handler within the Flash movie ---> <cfset FLASH.result = merchQuery> As you can see, this is a very simple template. The <cfparam> tag makes sure that Flash provides a parameter called MerchID . Then a simple query retrieves information from the corresponding record of the Merchandise table, and the query is passed back to Flash with FLASH.result . The only thing of note here is the fact that the MerchPrice column of the query is changed to hold the curren- cy-formatted version of the price. This is done because the lsCurrencyFormat() function is easy to use in ColdFusion, but has no direct equivalent in Flash. This underscores the fact that you can use any of the tools available to you as a ColdFusion developer within a page that serves Flash via Flash Remoting. Calling CFC Methods from Flash As you have seen, Flash Remoting makes it really easy to create ColdFusion pages that supply information to Flash, or perform whatever other type of processing you want to trigger from movies playing in the Flash Player. Just think of each directory that contains such ColdFusion pages as a service, and of each individual page as a service function. Flash Remoting also makes it possible to use ColdFusion Components to supply information or other server-side processing to Flash. Nearly everything you do on the Flash side of things is exactly the same. The only difference is that each CFC constitutes a service, and each of the CFC's methods constitutes service functions. In other words, you can think of a service as a collection of functions. Whether you want to write those functions as pages in a directory or as methods of a CFC is up to you. Of course, if you go the CFC route, you get all the other benefits of CFCs for free, including automatic docu- mentation and integration with Dreamweaver. But the greatest benefit of going the CFC route is the fact that your CFCs can be used internally by your ColdFusion pages (via the <cfinvoke> tag) or as Web Services, as well as by your Flash applications. See Chapter 22 for details about ColdFusion Components. 871