Daemon

 
Home / Services / Adobe Training / Tips & Tricks / Flash Remoting Section

Easy Flash Remoting Part Two

Author: Andrew Muller

Results being returned by Flash Remoting can be easily handled within the Flash movie via ActionScript. The result is received as a variable named after the function called with "_Result" appended at the end of the name.

In the previous example code we called a custom function getDepartments, if this function returns a result we should be able to anticipate it by writing a custom function in our Flash movie which will be triggered by the receipt of getDepartment_Result.

Here is that function; we declare it first with the ActionScript command function. Within parenthesis after that function name we define a parameter that will store the value returned from the server. The code in this function will loop over an array displaying the department key from the structure embedded within the array.

Flash Remoting results custom function
Flash Remoting results custom function

The getDepartments method of the CFC that we have called on the server runs a query that selects a list of departments from the demo database installed with ColdFusion MX. This query result set is converted into a complex data structure before being sent to the Flash movie.

Query result sets are structures, sometimes also known as associative arrays, with keys that include the number of records returned by the query and the query result itself.

The query result set is returned in a key called items which contains an array. Each index of the array is a row returned by the query, the index contains a structure which stores the database table columns retrieved by the query and a record id number.

The NetConnect Debugger, installed as part of the Flash Remoting components package, allows the developer to visualise the contents of the data returned to the Flash movie by the Flash Remoting service during development. This is one of the best tools available to the Flash Remoting developer.

This debug information is enabled by the use of the NetDebug.as object.

NetConnect Debugger
NetConnect Debugger

In the illustration above you will see an example of a query result set being returned from Flash Remoting to the Flash movie.

The first key of the Result object, mRecordsAvailable, contains the number of records returned by the query. The fourth key, items is an array that contains the query result set returned from the server.

In each index of this array there is a key named "department" which is the name of a database column returned by the query.

Result.items[0].department contains the value of the first department "Development".

Flash Remoting results custom function
Flash Remoting results custom function

In the custom function for getDepartments_Result we running a for loop to iterate over the indexes of the "items" array. Nested in that loop we are using the trace function to dump the department column data to the screen via an output window that will appear when we run the Flash movie within Flash MX by pressing Ctrl + Enter.

Output window
Output window

Completed code
Completed code

Easy Flash Remoting part three discusses displaying the values received into the Flash movie using ActionScript.

Download the files for this article. (113kb)

Daemon now does Macromedia certified Flash MX training

Menu

Social Profiles