Using the Flash Remoting service with ColdFusion Java objects

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.

To add a directory to ColdFusion classpath:

  1. Open the ColdFusion Administrator.
  2. In the Server Settings menu, click the Java and JVM link.
  3. Add your directory to the Class Path form field.
  4. Click Submit Changes.
  5. Restart ColdFusion.

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".

Comments