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

Home > Articles

  • Print
  • + Share This

Exercise 3: The Flash Movie, "FCS_Secure.fla"

Let's start with the interface (keep it simple). Use Figure 7 as your layout guide. Here are the elements you need:

  • Two input text boxes with the names defined in the property window as "login_txt" and "password_txt".

  • A Push Button UI Component with the ClickHandler entered as "login_init".

  • A PeopleList Communication UI Component. Give it the name "peopleList_mc" in the property window of the object.

  • A ConnectionLight Communication UI Component. Give it the name "connectionLight_mc" in the property window of the object.

  • A Dynamic Text Box with the name "status_txt".

  • Finally, place some text labels and any other graphics that might help people use this application on the screen.

Figure 7Figure 7 The Flash Interface for this Project. Use this as your layout guide for Exercise 1.

Now that your interface is set up, let's build the Flash ActionScript. Because there are a few methods to this exercise, they have been kept within the context of their function grouping. The following ActionScript should be placed within a single frame. Don't forget to put the stop(); command at the bottom of the script; you don't want any erroneous loops!

  1. First, insert the Flash Remoting Scripting objects into the Flash Movie. We'll also include the NetDebug objects so we can engage the NetConnection Debugger.

    // initialize the Flash Remoting Scripting Objects, 
    and the NetConnection Debugger
    #include "NetServices.as"
    #include "NetDebug.as"
  2. Next, instantiate the NetConnection Object (used to connect the Application to the Flash Communication Server) to a global variable called my_nc. You will not connect to the server just yet. Set up the NetConnection onStatus handler so you can watch any information objects coming in from the server. Lastly, connect the connectionLight to the NetConnection.

    // initialize the FlashCom NetConnection Object
    _global.my_nc = new NetConnection();
    _global.my_nc.onStatus = function(info_Obj) {
       trace(info_Obj.code);
    };
    connectionLight_mc.connect(my_nc);
  3. Finally, set up the Flash Remoting Gateway and set the path to the ColdFusion Component you created earlier. Remember that the folders the CFC is located in are separated with a dot syntax. This ColdFusion MX call uses the secure HTTPS protocol (see red, below), so transmission of information is secure.

    //initialize the Flash Remoting MX Object
    NetServices.setDefaultGatewayUrl("https://localhost/
    flashservices/gateway");
    gatewayConnection = NetServices.createGatewayConnection();
    cf_service = gatewayConnection.getService(
    "flashcom.applications.informIT.FCS_Security", this);

Now that you have the initial objects set up, let's build the two functions required by the application. The functions are:

  • login_init: Used by the Push Button to call the remote service function using Flash Remoting MX

  • authenticateUser_Result: Used to handle the remote function return object, and to make the Flash Communication Server connection request

Place the following ActionScript below the code you scripted above.

Method 1: "login_init"

This method is used by the Push Button to assemble the login and password and then call the ColdFusion Component. By assembling the login and password values into an object, you can easily pass them to the ColdFusion Server. ColdFusion will see them as a normal structure.

login_init = function () {
   // set the values of the login and password text fields
   into an object that will be sent to ColdFusion
   userInfo_Obj = ( { login:login_txt.text, 
   password:password_txt.text } );
   // call the server function, authenticateUser, 
   passing the username and password object
   cf_service.authenticateUser(userInfo_Obj);
   // Update the Status Message
   status_txt.text = "retrieving TICKET FROM SERVER";
};

Method 2: "authenticateUser_Result"

This method is used to handle the return results from the Remoting function "authenticateUser". Figure 8 shows the structure of the object returned to Flash by the function.

Figure 8Figure 8 The ColdFusion Structure returned by the authenticateUser method is assembled automatically by Flash Remoting MX into an ActionScript Object with four properties.

The method first challenges the "ISLOGINOK" property of the return object for a Boolean value of true. If successful, the Communication Server connection request is sent along with the "TICKET" property value of the returned object. Once the request is made, the PeopleList UI Component is connected to the NetConnection Object.

this.authenticateUser_Result = function(ret_Obj) {
   trace("** Object Returned From the Server");

   if (ret_Obj["ISLOGINOK"] == "true") {
     // SUCCESS: Connect to the FlashCom Server
     trace("... sending Ticket Information to FlashCom Server");
     my_nc.connect("rtmp:/informIT/myInstance", ret_Obj["TICKET"]);
     // Connect the People List and other UI Components
     peopleList_mc.connect(my_nc);
     peopleList_mc.setUsername(ret_Obj["USERNAME"]);
     // Update the Status Message
     status_txt.text = "TICKET: "+ret_Obj["TICKET"];
     // Store the Ticket in the Global Scope of the Player, for future use
     _global.Ticket_obj = ret_Obj;
   } else {
     // ERROR: Login/Password failed
     trace(".!. The username and Password are incorrect");
     status_txt.text = "Login and Password are incorrect, please try again";
   }
};

Your last bit of ActionScript stops the play head from looping or continuing.

stop();

It may have looked like a lot of ActionScript when you first started, but as you can see there are a lot of complex processes involved. This script successfully manages communications for both the Flash Communication Server and the ColdFusion Flash Remoting gateway service. The next exercise will set up the main.asc file for the Flash Communication Server.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

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