Excerpted from Macromedia Flash Communication Server MX, 0735713332s. The communication flow from Player to Flash Communication Server to ColdFusion

Страницы работы

Фрагмент текста работы

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.

2.  // initialize the Flash Remoting Scripting Objects, 

3.  and the NetConnection Debugger

4.  #include "NetServices.as"

#include "NetDebug.as"

5.  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.

6.  // initialize the FlashCom NetConnection Object

7.  _global.my_nc = new NetConnection();

8.  _global.my_nc.onStatus = function(info_Obj) {

9.  trace(info_Obj.code);

10.  }; connectionLight_mc.connect(my_nc);

11.  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.

12.  //initialize the Flash Remoting MX Object

13.  NetServices.setDefaultGatewayUrl("https://localhost/

14.  flashservices/gateway");

15.  gatewayConnection = NetServices.createGatewayConnection(); 16. 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 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

Похожие материалы

Информация о работе