This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
The Life of an Application Instance
|
125
Notice that there are two key objects related to instance and client management. The
application object is a singleton object—there is only one—that represents the
application instance. Each instance gets its own
application object, which is an
instance of the Application class. As shown in Example 4-2, you should add dynamic
methods directly to the singleton instance,
application, instead of Application.
prototype
. For example:
application.onConnect = function (client, userName, password) {};
A Client object represents a client-side Flash movie attempting to connect to an
application instance. There can be more than one Client object (one for each user)
for each
application object. The methods and properties of the Application and Cli-
ent classes are described in Macromedia’s Server-Side Communication ActionScript
Dictionary (available from http://download.macromedia.com/pub/flashcom/
documentation/FlashCom_SS_ASD.pdf).
Here is the startup sequence:
1. The main.asc file is loaded, compiled, and executed.
2. Any files that were included using the load( ) method are loaded and executed.
In turn, these files may load other files.
3. The application.onAppStart( ) method is called. The onAppStart( ) method is
called only once and is often used to initialize the
application object and the
instance’s shared object and stream resources.
4. If the instance has been started as a result of a client connection request using
NetConnection.connect( ), the application.onConnect( ) method is called and
passed a Client object, representing the client Flash movie that tried to connect.
Any optional parameters passed into connect( ) are also forwarded to the onCon-
nect( ) method, where the client’s connection request can be rejected, accepted,
or left pending.
Midlife
Once the application instance has started, any number of clients can connect and
disconnect from the instance. Whenever a Flash movie attempts to connect, the
application.onConnect( ) method is called and passed a new Client object represent-
ing the client-side Flash movie. Client objects with accepted connections are kept in
the
application.clients array. Whenever an accepted client disconnects, the appli-
cation.onDisconnect( ) method is called and passed a Client object that represents the
client that has disconnected. A client can be disconnected due to network problems
or problems on a remote workstation. FlashCom may not realize immediately that
the client has disconnected. So, it is possible that, for a time, a Client object will not
always represent a connected movie.

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.