Publishers of technology books, eBooks, and videos for creative people

Home > Articles

  • Print
  • + Share This

Exercise 4: The Server-Side ActionScript, "main.asc"

This final exercise will construct the main.asc file on the server. This file must be placed within the InformIT folder in the FlashCom/Applications folder. Remember, SSAS is case sensitive, so your first debugging check always involves checking capitalization.

  1. First, include the netservices class library to enable Flash Remoting from the Flash Communication Server. Load the components class library as well, because we are using some prebuilt Communication UI components.

    // Load the NetServices Class Libraries
    load("netservices.asc");
    load("components.asc");
  2. There are a number of ways you could do the next few steps; however, to keep this article short and easy, I've decided to place all actions for this application within the application.onConnect() function. This function is called whenever a client (Flash Player) requests a connection to the Flash Communication Server Application instance.

  3. This application.onConnect method will require the parameter "ticket_hash" to be received. Flash Player sends this value within the connect() function; it is the same value that was received by Flash from the ColdFusion Server.

    application.onConnect = function(clientObject, ticket_hash) {
  4. Next, set up the SSAS Flash Remoting objects pointing to the same ColdFusion Flash gateway service you used within Flash MX. Like the ActionScript used earlier in Flash MX, this ColdFusion MX call uses the secure HTTPS protocol, so transmission of information is secure. In this script, we've chosen to even use the same local object name, "cf_service".

      /* --- Flash Remoting Setup --- */
      trace("Connecting to remoting Server..");
      NetServices.setDefaultGatewayUrl( "https://localhost/
      flashservices/gateway");
      var gatewayConnection = NetServices.createGatewayConnection();
      var cf_service = gatewayConnection.getService(
      "flashcom.applications.informIT.FCS_Security", this);
      /* --- End Flash Remoting Setup */
  5. Now that Flash Remoting is set up, call the remote service method, "findTicket", passing the value of "ticket_hash" argument that was received from the Flash Player.

       //call the server function, authenticateUser, 
       passing the username and password
       var callTheServer = cf_service.findTicket(ticket_hash);
  6. Flash Communication Server will wait until either a successful result or a failed onStatus is received from the Flash Remoting Gateway (ColdFusion). This function handles the results returned from the ColdFusion server. The name of the function is the name of the service method (findTicket) with a "_Result" appended to the end of the name.

The ActionScript object sent from ColdFusion contains two properties (see Figure 9): ISTICKETOK, a Boolean value that tells Flash Communication Server if the ticket sent was valid, and if it was, a second property, "USERNAME", is sent containing the value of the user's name.

This function will challenge the property ISTICKETOK. If it returns true, it will accept the connection request and register the username with the Framework used by the Communication UI Components. If a value of false is received, the connection is rejected.

     // handle the Remoting response
   this.findTicket_Result = function(result_obj) {
     trace(":: The Server Responded --> "+ result_obj["ISTICKETOK"]);
     trace("  --> User name has been set to: "+ result_obj["USERNAME"]);

     if (result_obj["ISTICKETOK"]) { // server responded TRUE
        trace("You have entered the inner sanctum");
        application.acceptConnection(clientObject);
        // register the user in the UI Framework
   gFrameworkFC.getClientGlobals(clientObject).username = 
        result_obj["USERNAME"];
        } else { // Server responded FALSE
          trace("Not today, my Furry Friend...");
   application.rejectConnection(clientObject);
        }
     };

Figure 9Figure 9 The ColdFusion Structure returned by the findTicket method is assembled automatically by Flash Remoting into an ActionScript Object with two properties.

It is important to remember that all properties returned from ColdFusion will always be in uppercase, and because SSAS is case sensitive, this is important.

// Don't forget to close the onConnect function !!!
};

That's it for the SSAS. Now, in most cases, you should have an onStatus function for the Remoting calls, but to save some space in this article, it was omitted.

Next up, it's time to test the full application.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.