Adobe ColdFusion 8

Handling errors with ColdFusion and Flash

To help with debugging, use tags in your ColdFusion page or component to return error messages to the Flash Player. For example, the ColdFusion page, causeError.cfm, contains the code:

<cftry>
    <cfset dev = Val(0)>
    <cfset Flash.Result = (1 / dev)>
    <cfcatch type = "any">
        <cfthrow message = "An error occurred in this service: #cfcatch.message#">
    </cfcatch>
</cftry>

The second cfset tag in this example fails because it tries to divide by zero (0). The message attribute of the cfthrow tag describes the error; ColdFusion returns this attribute to the Flash application.

To handle the error in your Flash application, create a fault handler similar to causeError_Fault in the following example:

import mx.remoting.*;
import mx.services.Log;
import mx.rpc.*; 

// Connect to service and create service object
    var CFMService:Service = new Service(
            "http://localhost/flashservices/gateway",
            null,
            "helloExamples",
            null, 
            null );
// Call the service causeError() method
var pc:PendingCall = CFMService.causeError();
// Tell the service what methods handle result and fault conditions
pc.responder = new RelayResponder( this, "causeError_Result", "causeError_Fault" );

function causeError_Result(re:ResultEvent)
{
    // Display successful result
    messageDisplay.text = re.result;
}

function causeError_Fault(fe:FaultEvent)
{
    // Display fault returned from service
    trace("Error message from causeError is: " + fe.fault.description);
}

This example displays the trace message from the causeError_Fault function in the Flash Output panel. The portion of the message that is contained in fe.fault.description is the portion of the message that is contained in #cfcatch.message# in the causeError.cfm page.

Note: When you create a ColdFusion page that communicates with Flash, ensure that the ColdFusion page works before using it with Flash.