This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Running a Simple Hello World Test Script
|
127
Example 4-2 shows a short main.asc script that is the SSAS implementation of
helloWorld. It demonstrates all the standard event handler methods of the
application object.
With this example code in mind, let’s take a closer look at the most important event
handling methods of the
application object. These are invoked automatically when
the application starts, when a client attempts to connect, when a client disconnects,
or when the application is supposed to shut down.
application.onAppStart( )
When an application instance is accessed the first time, the script is compiled and
any global code (i.e., code outside the context of an event handler) is executed. After
that, the application.onAppStart( ) method is called. In Example 4-2, the
application.name property is used to output the name of the instance that has been
Example 4-2. A simple server-side helloWorld test script
application.onAppStart = function ( ) {
trace("onAppStart> " + application.name + " is starting at " + new Date( ));
};
application.onStatus = function (info) {
trace("onStatus> info.level: " + info.level + ", info.code: " + info.code);
trace("onStatus> info.description: " + info.description);
trace("onStatus> info.details: " + info.details);
};
application.onConnect = function (client, userName, password) {
client.userName = userName;
client.writeAccess = "/public";
client.readAccess = "/";
application.acceptConnection(client);
trace("onConnect> client.ip: " + client.ip);
trace("onConnect> client.agent: " + client.agent);
trace("onConnect> client.referrer: " + client.referrer);
trace("onConnect> client.protocol: " + client.protocol);
};
application.onDisconnect = function (client) {
trace("onDisconnect> client.userName: " + client.userName)
trace("onDisconnect> disconnecting at: " + new Date( ));
};
application.onAppStop = function (info) {
trace("onAppStop> application.name: " + application.name);
trace("onAppStop> stopping at " + new Date( ));
trace("onAppStop> info.level: " + info.level);
trace("onAppStop> info.code: " + info.code);
trace("onAppStop> info.description: " + info.description);
};

Get Programming Flash Communication Server now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.