The rest of this chapter will introduce a number of miscellaneous topics related to Flash Remoting that I think you'll find interesting. Please refer to the Flash and ColdFusion documentation for the details. Debugging Flash Remoting ProjectsThe Flash Remoting Components include a special debugging tool called the NetConnection Debugger. This clever programming aid lets you monitor the interactions between your Flash applications in real time. Conceptually, the NetConnection Debugger is similar to the Server Debug window in Dreamweaver ; its purpose is to make your life easier while building applications, especially complex ones. To use the NetConnection Debugger, follow these steps:
The NetConnection Debugger window will show information about each interaction between Flash and your ColdFusion server (Figure 26.11). You see the same type of information here that you would normally see at the bottom of a ColdFusion page when you have the debugging options turned on. You can view SQL statements and query results as they take place on the server, the total execution time of each service function call, and more. This information can be incredibly helpful if you are trying to track down problems or performance bottlenecks in your application. Figure 26.11. The NetConnection Debugger makes it easier to monitor and troubleshoot your Flash Remoting projects.NOTE Make sure to exclude the NeTDebug.as file before you make your Flash application public. This reduces the size of your Flash movie file. You can send helpful trace messages from the ColdFusion server to the NetConnection Debugger window by simply using the <cftrace> tag. For instance, if you add the following line to the MerchDetailProvider function in Listing 26.9, then the debugger will display the "Hello from ColdFusion" message. The Data Glue ObjectYou can use the Data Glue object to bind RecordSet objects to ListBox and other controls in your movies. This allows you to simply tell the Flash Player to display whatever data is in a recordset in a ListBox, without having to write the looping code that would otherwise be required. For instance, you can replace the following lines of code in Listing 26.5: function MerchRecordsetProvider_Result(result) { // First, remove any existing items from the list box MerchListBox.removeAll(); // For each record in the recordset... for (var i = 0; i < result.getLength(); i++) { // Use the record variable to refer to the current row of recordset var record = result.getItemAt(i); // Add item to the MerchListBox widget, which is like a <SELECT> in HTML MerchListBox.addItem(record.MerchName, record.MerchID); }; } with this: function MerchRecordsetProvider_Result(result) { DataGlue.bindFormatStrings(MerchListBox, result, "#MerchName#", "#MerchID#"); } To use this line, you just need to add #include "DataGlue.as" at the top of the code. The DataGlue.as file was installed along with the Flash Remoting Components. DataGlue offers many other benefits as well. For more information about DataGlue, choose Help > Welcome to Flash Remoting from the Flash's menu, and look in the Flash Remoting ActionScript Dictionary part of the documentation that appears. You can also find the same information in the Reference panel under the Remoting topic. Incrementally Loading RecordsetsIf you want to send very large recordsets from ColdFusion to Flash, you may want to deliver and display a certain number of rows at a time, rather than requiring the Flash Player to wait until it has received the entire recordset. The Flash Remoting framework makes it surprisingly easy to work with recordset data right away, even if the entire recordset hasn't yet been received. To return records incrementally from ColdFusion, use the special FLASH.PageSize variable. For instance, to send a recordset back to Flash ten rows at a time, include this line in your ColdFusion code before you return the recordset with FLASH.result or <cfreturn>: <cfset FLASH.pageSize = 10> Once you are sending records back to Flash incrementally, you may have to adapt the ActionScript code that works with the records. For instance, in loops, you will often need to use the getNumber Available() method, which returns the number of records that have actually been received, instead of getLength(), which includes records that have not yet been received. You'll have to make a number of other changes, which lie beyond the scope of this book. NOTE When possible, use the DataGlue object (discussed in the previous section, "The Data Glue Object") to bind recordsets to ListBoxes or other visual components once you are using incremental recordsets. The DataGlue framework will take care of displaying the records as they are received. That way, you don't have to worry about checking for the current number of records in your code. For more information about incrementally receiving recordsets on the Flash side, choose Help > Welcome to Flash Remoting from the Flash's menu and look in the Flash Remoting ActionScript Dictionary part of the documentation that appears. Pay particular attention to the setDeliveryMode() and getNumberAvailable() methods of the RecordSet object. You can also find the same information in the Reference panel under the Remoting topic. TIP Once you set FLASH.pageSize, you can watch the records coming back to Flash in the smaller groups with the NetConnection Debugger. Security and Logging In from FlashIf you want to secure the information you are providing from ColdFusion to Flash, you can do so using portions of the <cflogin> framework introduced in Chapter 21, "Securing Your Applications." For instance, if you log in your users with <cflogin> and <cfloginuser> and supply role names to the roles attribute of your CFC's <cffunction> blocks, then only the users assigned to the appropriate roles can access the methods, even through Flash. To try this out, edit this chapter's Application.cfc file so that it forces the user to log in via the ForceUserLogin.cfm template from Chapter 21 by adding this <cfinclude> tag: <!--- Force the user to log in ---> <cfinclude template="../21/ForceUserLogin.cfm"> Now add a roles="Admin" attribute (careful, Admin is case sensitive) to the <cffunction> tags in Listing 26.9. Publish the Merchandise Browser movie, but rename the generated HTML file to MerchBrowser.cfm so that ColdFusion will process the page. Now visit MerchBrowser.cfm with your browser. You should be forced to log in. If you log in as an Admin user (for example, with user name Ben and password Forta), you will be permitted to see the list of products. If you log in as a non-Admin user, the list of products will never appear.
The roles attribute is for CFCs and UDFs only (see Appendix B, "ColdFusion Tag Reference," for details). You can also use the IsUserInRole() function to secure normal ColdFusion pages that supply data to Flash (see Chapter 18 for details about IsUserInRole()). TIP You can watch the process succeed or fail, and check out messages about users' failure to log in properly, in the NetConnection Debugger. Other Integration MethodsThis chapter has introduced you to the brave new world of Flash Remoting, which enables you to integrate ColdFusion and Flash in a feature-rich, sophisticated way. It's also possible for Flash to grab information from a ColdFusion server using the somewhat more humble LoadVariables(), available to Flash developers for years. Before Flash and Flash Remoting, this was the primary way for the Flash Player to interact with servers via the Internet. NOTE Actually, there are two forms of this function: LoadVariables() and LoadVariablesNum(). For purposes of this discussion, consider them synonymous. See the Flash documentation for details. |