8.a Appendix: Actionscript Extension Template
| The source of this example is found in the Examples/(Flash version)/applicationTemplate folder. |
» Introduction
This article provides a basic template for creating your you own server side extensions using Actionscript.
» Actionscript Extensions in a nuthshell
Basically an extension has four different tasks to accomplish:
1) Initialize
2) Handle client requests
3) Handle internal server events
4) Destroy
These four tasks are handled respectively by four Actionscript functions
called: init(), handleRequest(), handleInternalEvent(), destroy()
These four functions should always be declared in your
extensions, even if they don't contain code.
» The template
Here's the code of the extension template:
/*
* Initializion point:
*
* this function is called as soon as the extension
* is loaded in the server.
*
* You can add here all the initialization code
*
*/
function init()
{
trace("Extension initialized")
}
/*
* This method is called by the server when an extension
* is being removed / destroyed.
*
* Always make sure to release resources like setInterval(s)
* open files etc in this method.
*
* In this case we delete the reference to the databaseManager
*/
function destroy()
{
trace("Extension destroyed")
}
/*
*
* Handle Client Requests
*
* cmd = a string with the client command to execute
* params = list of parameters expected from the client
* user = the User object representing the sender
* fromRoom = the id of the room where the request was generated
*
*/
function handleRequest(cmd, params, user, fromRoom)
{
// Add your code here
}
/*
* This method handles internal events
* Internal events are dispactched by the Zone or Room where the extension is attached to
*
* the (evt) object
*/
function handleInternalEvent(evt)
{
// Add your code here
}
| doc index |