After you connect to the Flash Remoting service, you call functions that are defined in your server-side ActionScript files, and return results.
Call a function
Create an instance of the server-side ActionScript file using the getServicefunction. This function instantiates the server-side ActionScript file as an object to use on the client side. For example:
albumService = gatewayConnection.getService("recordsettest", this)
Where recordsettest represents the name of the server-side ActionScript file, without the filename extension .asr.
Call a function defined in your server-side ActionScript object. Use dot notation to specify the object name followed by the function name; for example:
albumService.getAlbum("The Color And The Shape", "1999");
Where albumService is the instance of the server-side ActionScript file and getAlbum is a function that passes two arguments, "The Color and The Shape" and "1999".
Note: Arguments must occur in the order defined in the function declaration.
- Handle the function results in ActionScript. See Using the function results in ActionScript below.
Using the function results in ActionScript
To use the results returned by server-side ActionScript, create a corresponding results function. The results function uses a special naming convention that ties it to the function that calls the server-side ActionScript. For example, if you defined a client-side ActionScript function called basicCustomerQuery, you also must create a results function called basicCustomerQuery_Result.
The results returned by server-side ActionScript functions differ somewhat depending on whether you are using CF.http or CF.query:
- The CF.query function returns a record set, which you manipulate using methods available in the RecordSet ActionScript class object. See Using results returned by the CF.query function section.
- The CF.http function returns simple text strings through properties that you reference in your server-side ActionScript. See Using results returned by the CF.http function section.
Using results returned by the CF.query function
You use functions in the RecordSet ActionScript object to access the data returned in a CF.query record set; for example, how many records are in the record set and the names of the columns. You can also use the RecordSet functions to pull the query data out of the record set. To do so, you reference a specific row number in the record set and use the getItemAt RecordSet function, as in the following example:
// This function populates a Flash text box with data in the first row
In the example, the column name is referenced in the getItemAt function between square brackets [ ]. (In ActionScript, indexes start at 0, so getItemAt(0) returns the first row.)For more information, see Using the CF.query function.
Using results returned by the CF.http function
The CF.http server-side ActionScript function returns data as simple text. You write server-side functions that reference the properties available in the object returned by the CF.http function. These properties store the file content of the retrieved file, HTTP status codes, the MIME type of the returned file, and so on. On the client side, you create return functions to handle data returned by the CF.http function. You write these functions to handle simple text data. For more information, see Using the CF.http function.