O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

14.15. Tracking Clients Connected to the Application

Problem

You want to keep track of all the clients connected to the FlashCom application.

Solution

Use the server-side application.clients property.

Discussion

Server-Side ActionScript (for FlashCom) includes a built-in, application-wide property named application.clients, which is an array of all the connected client objects.

This example defines a custom getUserInfo( ) method, for each client, which returns information about the clients connected to the application:

// Create an application.onConnect(  ) method. This example assume that when the client
// connects, a username parameter is passed along.
application.onConnect = function (newClient, username) {
  
  // Accept the connection to the new client.
  application.acceptConnection(newClient);

  // Add the username to the client object as a custom property.
  newClient.username = username;

  // Define a custom getUserInfo(  ) method for the client object. This method can then
  // be called from the client.
  newClient.getUserInfo = function (  ) {

    // Create a new array, loop through all the connected clients in
    // application.clients and add the usernames to the array.
    var clients_ar = new Array(  );
    for (var i = 0; i < application.clients.length; i++) {
      clients_ar.push(application.clients[i].username);
    }
    // Return the array of usernames.
    return clients_ar;
  };
};

See Also

Recipe 14.14

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required