
30
When you call NetConnection.call from a client-side ActionScript script, the method that
executes in the server-side script must be a method of the Client object. 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 you define in the server-side script directly from the Client object instance in the server-
side script.
If all instances of the Client object (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. You can extend any server-side or
client-side ActionScript class. To extend a class, instead of defining methods inside 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.
Extending a class lets you define the methods of a class separately, which makes them easier to
read in a script. And more importantly, it is more efficient to add methods to
prototype,
otherwise the methods are reinterpreted each time an instance is created.
The following code shows how to assign methods and properties to an instance of a class. During
application.onConnect, a 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
}
};
Komentarze do niniejszej Instrukcji