
ADOBE FLASH MEDIA INTERACTIVE SERVER
Server-Side ActionScript Language Reference
30
Returns
A boolean value indicating success (
true) or failure (false).
Client class
The Client class lets you handle each user, or client, connection to a Flash Media Server application instance. The
server automatically creates a Client object when a user connects to an application; the object is destroyed when the
user disconnects from the application. Users have unique Client objects for each application to which they are
connected. Thousands of Client objects can be active at the same time.
You can use the properties of the Client class to determine the version, platform, and IP address of each client. You
can also set individual read and write permissions to various application resources such as Stream objects and shared
objects. Use the methods of the Client class to set bandwidth limits and to call methods in client-side scripts.
When you call
NetConnection.call() from a client-side ActionScript script, the method that is executed in the
server-side script must be a method of the Client class. In your server-side script, you must define any method that
you want to call from the client-side script. You can also call any methods that you define in the server-side script
directly from the Client class instance in the server-side script.
If all instances of the Client class (each client in an application) require the same methods or properties, you can add
those methods and properties to the class itself instead of adding them to each instance of a class. This process is
called extending a class. To extend a class, instead of defining methods in the constructor function of the class or
assigning them to individual instances of the class, you assign methods to the
prototype property of the constructor
function of the class. When you assign methods and properties to the
prototype property, the methods are
automatically available to all instances of the class.
The following code shows how to assign methods and properties to an instance of a class. In the
application.onConnect() handler, the client instance clientObj is passed to the server-side script as a
parameter. You can then assign a property and method to the client instance.
application.onConnect = function(clientObj){
clientObj.birthday = myBDay;
clientObj.calculateDaysUntilBirthday = function(){
// Insert code here.
}
};
The previous example works, but must be executed every time a client connects. If you want the same methods and
properties to be available to all clients in the
application.clients array without defining them every time, assign
them to the
prototype property of the Client class.
There are two steps to extending a built-in class by using the
prototype property. You can write the steps in any
order in your script. The following example extends the built-in Client class, so the first step is to write the function
that you will assign to the
prototype property:
// First step: write the functions.
function Client_getWritePermission(){
// The writeAccess property is already built in to the Client class.
return this.writeAccess;
}
function Client_createUniqueID(){
var ipStr = this.ip;
Commenti su questo manuale