This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Using Flash Remoting to Log Events
|
447
// Define a client method that simply returns an array of connected users.
// Write a log event each time the method is called.
Client.prototype.getUserList = function ( ) (
this.logger.log("get_user_list", "Client requested user list.",
{client: this.username, ip: this.ip});
return application.clients;
};
The application code is fairly straightforward and doesn’t require much additional
explanation. It creates PFCSLogger instances—one as a property of the
application
object and one as a property of each connected client. The application logger logs
events when the application starts and stops. Additionally, and simply for testing
purposes, the application uses setInterval( ) to log poll events once per minute. The
client logger logs events when clients connect, disconnect, or call the getUserList( )
method.
Creating the Flash Client
In order to test the application and the loggers, you next need to create a Flash movie
to serve as the client. The client is very simple. It should contain two component
instances—a Button component named
cbt and a List component named user_list.
Create a file named loggerClient.fla, add the two components using the Components
panel, and give them instance names using the Properties panel. Then, rename the
first layer to Actions and add the following ActionScript code to the first frame of the
layer on the main timeline:
// Define a response object to handle responses from FlashCom client method calls.
var response = new Object( );
response.onResult = function (data) {
// When an array of users is returned, assign it to the data provider of the list.
user_list.dataProvider = data;
};
// Define a listener object to handle click events dispatched by the button.
var listener = new Object( );
// When a user clicks the button, call FlashCom application's getUserList( ) method.
listener.click = function ( ) (
nc.call("getUserList", response);
};
// Register the listener object with the button.
cbt.addEventListener("click", listener);
// Create the NetConnection.
var nc = new NetConnection( );
// Connect to the application with a username of “some_user”.
nc.connect("rtmp:/fcs_log", "some_user");

Get Programming Flash Communication Server now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.