MACROMEDIA FLASH COMMUNICATION SERVER MX-SERVER-SIDE COMMUNICATION ACTIONSCRIPT DICTIONARY Manual page 24

Server-side communication actionscript dictionary
Table of Contents

Advertisement

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
methods and properties to the
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
otherwise the methods are re-interpreted each time an instance is created.
The following code shows how to assign methods and properties to an instance of a class. During
application.connect
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 above 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
without defining them every time, you must assign them to the
object There are two steps to extending a built-in class using the
write the steps in any order in your script. The following example extends the built-in Client
object, so the first step is to write the function that you will assign to the
// first step: write the functions
function Client_getWritePermission(){
// "writeAccess" property is already built-in to the client class
return this.writeAccess;
}
function Client_createUniqueID(){
var ipStr = this.ip;
// "ip" property is already built-in to the client class
var uniqueID = "re123mn"
// you would need to write code in the above line
// that creates a unique ID for each client instance
return uniqueID;
}
// second step: assign prototype methods to the functions
Client.prototype.getWritePermission = Client_getWritePermission;
Client.prototype.createUniqueID = Client_createFriendlyUniqueID;
// a good naming convention is to start all class method
// names with the name of the class, followed by an underscore
You can also add properties to
Client.prototype.company = "Macromedia";
property of the constructor function of the class. When you assign
property, the methods are automatically available to all
prototype
, a client instance
clientObj
, as shown in the following example:
prototype
is passed to the server-side script as a
application.clients
property of the Client
prototype
prototype
prototype
Server-Side Communication ActionScript
,
prototype
array
method. You can
property:
25

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH COMMUNICATION SERVER MX-SERVER-SIDE COMMUNICATION ACTIONSCRIPT DICTIONARY and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash communication server mx

Table of Contents