Testing and Debugging

With the first stages of the project completed and all parts in working order, the application should be tested. In the case of our ScriptRepository.as file, some built-in methods of the application and the objects used in the application make our life easier. We have defined toString( ) methods of the two main objects, and also a test( ) method to make sure that the object coming back from remote services has been cast to the correct datatype.

To use the toString( ) method, simply sprinkle the code with the following, substituting the object name:

trace(myObject.toString( ));

This can even be used in the init( ) method of your constructor to make sure your objects are being instantiated properly and at the right times:

trace(this.toString( ));

The test( ) method is used in the responder onResult( ) method. Simply call the test( ) method on the result coming from the remote service. If the result has been cast to the correct object type, the test( ) method will fire. If it hasn’t been cast properly, the method will not fire:

ScriptObject.prototype.onResult = function (result) {
  result.test( );
  // more code...
}

During testing we also set up a special server-side logging method to log each object that was being created on the server. The server-side code is shown in Example 14-16 and shows how easy it is to create a custom log file for a custom object.

Example 14-16. Server-side logging code
<cffunction access="remote" name="objToString" output="false" returntype="string" ...

Get Flash Remoting: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.