Using the Flash Remoting service with ColdFusion Java objects

You can run various kinds of Java objects with ColdFusion, including JavaBeans, Java classes, and Enterprise JavaBeans. You can use the ColdFusion Administrator to add additional directories to the classpath.

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 SWF 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 UIComponents() 
    { 
    } 
    public String sayHello() 
    { 
        return "Hello"; 
    } 
}
Note: You cannot call constructors with Flash Remoting. Use the default constructor.

In ActionScript, the following javaService call runs the sayHello public method of the utils.UIComponents class:

import mx.remoting.*; 
import mx.services.Log; 
import mx.rpc.*;  
 
// Connect to service and create service object 
    var javaService:Service = new Service( 
            "http://localhost/flashservices/gateway", 
            null, 
            utils.UIComponents", 
            null,  
            null ); 
// Call the service sayHello() method 
var pc:PendingCall = javaService.sayHello(); 
// Tell the service what methods handle result and fault conditions 
pc.responder = new RelayResponder( this, "sayHello_Result", "sayHello_Fault" ); 
 
function sayHello_Result(re:ResultEvent) 
{ 
    // Display successful result 
    trace("Result is: " + re.result); 
} 
 
function sayHello_Fault(fe:FaultEvent) 
{ 
    // Display fault returned from service 
    trace("Error is: " + fe.fault.description); 
}
Note: For more information about using Java objects with ColdFusion, see Using Java objects