You can run various kinds of Java objects with ColdFusion MX, including JavaBeans, Java classes, and Enterprise JavaBeans. You can use the ColdFusion Administrator to add additional directories to the classpath.
When you place your Java files in the classpath, the public methods of the class instance are available to your Flash movie.
For example, assume the Java class utils.UIComponents
exists in a directory in your ColdFusion classpath. The Java file contains the following code:
package utils;
public class UIComponents { public String sayHello() { return "Hello"; } }
Note: You cannot call constructors with Flash Remoting. You must use the default constructor.
In ActionScript, the following getService
call invokes the sayHello
public method of the utils.UIComponents
class:
#include "NetServices.as"
NetServices.setDefaultGatewayUrl("http://localhost:8500/flashservices/gateway"); gatewayConnection = NetServices.createGatewayConnection(); javaService = gatewayConnection.getService("utils.UIComponents", this); javaService.sayHello(); function sayHello_Result(result) { trace(result); }
Note: For more information about using Java objects with ColdFusion, see Chapter 32, "Using Java objects".