This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
124
|
Chapter 4: Applications, Instances, and Server-Side ActionScript
ActionScript 2.0. Again, see Essential ActionScript 2.0 for a full discussion of client-
side ActionScript classes and packages.
The Life of an Application Instance
An application instance is a process that runs in FlashCom. Each instance has:
Its own script engine
A namespace of streams and shared objects
Persistent data that can be stored within its namespace
No two instances can share or update the same data directly, but they can play the
same stream in a virtual stream directory (see Chapter 5).
FlashCom maintains a pool of threads for script processing, and each application
uses one thread from this pool to execute server-side scripts in response to events
such as loading an instance or a Flash client connecting to an instance. Server-side
scripts should be designed to handle events quickly and then release the thread they
are using. When an error is thrown in one instance, it will not affect the other
instances.
FlashCom can run many different instances of the same application. Each instance is
usually created by FlashCom in response to a connection request from a client.
FlashCom receives the client’s connection request and examines the RTMP address
passed by the client to the server. The RTMP address forwarded by the client is the
URI passed into the client-side NetConnection.connect( ) method. As described in
Chapter 3, FlashCom extracts the application name and then runs an instance of the
application. If no instance name is provided in the RTMP address, it creates an
instance named
_definst_. Otherwise, it creates the instance named in the URI.
Depending on how the application is scripted and how the server is configured, some
time after the last client disconnects, the instance will be destroyed. Between the
time an instance is created and destroyed, a number of things can happen. To sim-
plify how things work, they are divided here into three sections: startup, midlife, and
shutdown.
Startup
An instance is normally started by FlashCom when the first client attempts to con-
nect to it. However, it may be started manually with the App Inspector or Adminis-
tration Console, or an application instance can be made to start immediately after
the server is started by setting the contents of the
<LoadOnStartup> tag in an Applica-
tion.xml file (see “Using load( ) to Include Other Script Files” later in this chapter for
details on where to place the Application.xml file).

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.