Tutorials

Flash Remoting (Object Passing) (Page 2 of 3)

There's not much to explain concerning the code except to say two query objects are created by hitting an Access database. Then, a structure is created that has one key for each of the query objects. It is the main structure returnStruct that the CFFUNCTION returns to the caller. There are two things to be aware of in this function. One, the function's access level is remote. This means the function could be invoked by ColdFusion from a .cfm, it could be called as a Web service, and (as in our case) called via FlashMX. The second thing to make note of is the returntype. The returntype and the datatype of the variable that is actually returned must match. In this case, we are working with a structure. Now that we have the function finished we can write our Flash code to call the function.

I created a Flash method called GetStructureOfQueries(). This method is responsible for calling the ColdFusion function GetStructureOfQueries outlined above. The Flash method looks like this:

//Method to test the retrieval of a structure of queries assembled from the
//bikeManager cfc.
function GetStructureOfQueries() {
	    //Call the method of the cfc that assembles the structure.
	    //The method requires no passed parameters.
	    BikeManager.GetStructureOfQueries();
}
	

Pretty simple stuff right? The _Result or callback function - that is automatically called by Flash after the CFC function runs - has all the code that parses the object that is returned to Flash. It looks like this:

function GetStructureOfQueries_Result(theStruct) {
    for (var i=0; i

When the callback function is executed the structure of queries that ColdFusion returns is stored in the Flash object theStruct. Then, I loop over the first query object and display all the values that ColdFusion returned. The object theStruct can be broken down into its various parts like this:

theStruct.GETBIKES - original query object.
theStruct.GETOILCHANGEHISTORY - original query object.

PREVIOUS | NEXT

RSS