This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Chapter 4: Applications, Instances, and Server-Side ActionScript
Regardless of the approach chosen, an additional authentication step should be used.
The short code snippet that follows can be placed in an onConnect( ) method to han-
dle instance connections before attempting to handle Flash movie connections.
The code assumes that a unique
userName is provided by the connecting instance so
that its
client object can be kept in an object named roomList. The unique name
could be the instance name of the room:
if (client.ip = "" && client.agent.indexOf("FlashCom") == 0) {
if (password == "room54780561Password") {
roomList[userName] = client;
return true; // Accept the connection
trace("Invalid room connection attempt.");
return false; // Reject the connection
For variety, connections are accepted or rejected by returning true or false from
within the onConnect( ) method in the preceding example.
Now that you have a better understanding of how to manage connections, let’s
examine some of the mechanics of locating code and configuration files.
Script Filenames and Locations in Detail
An application comprises one or more SSAS source code files (plain text files). Let’s
look closer at the file organization for a server-side application.
The main Application Script File
When an application instance starts, it looks for a main script file to run. The file can
have one of two names and can be stored in one of two locations. The file can be
named main with either an .asc or .js extension (main.asc or main.js) or it can have
the same name as the application’s home directory with either extension. For exam-
ple, if the application’s home directory name is courseChat and if no main.asc file
exists, the courseChat.asc file will be loaded. The main file can be stored in one of
two places: in the application’s home directory or in a subdirectory of the home
directory named scripts. Files with the .asc extension take precedence over .js files.
Using load( ) to Include Other Script Files
Once the main file has been loaded and any global code (code defined outside event
handlers such as onConnect( )) within it is executed, other source files can be loaded.
The load( ) method accepts the relative path of the external file to be compiled and
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Script Filenames and Locations in Detail
executed. For example, a main.asc file in an application’s home directory could load
a file in the scripts directory this way:
The relative paths cannot include the “..” characters to indicate moving up a level in
the directory tree, so there has to be another way to load source files that are com-
mon to more than one application. The FlashCom installer creates a directory named
scriptlib where the common script files provided by Macromedia are placed. The
scriptlib directory contains the files required for Flash Remoting and the communica-
tion components. If a file is not found in a path relative to the file that loads it, the
server will attempt to find it in a relative path starting from the scriptlib directory.
For example, when a main file loads the communication components, it calls:
Files can also be placed in subdirectories of the scriptlib directory. For example, the
.asc source files for the individual communication components are found in the
scriptlib/components directory.
The location of the scriptlib directory can be changed using the
<ScriptLibPath> tag
of an Application.xml file, and additional paths to other script library directories can
be added to it. For example, an Application.xml file can be placed in the home direc-
tory of an application. The default tag might look something like this depending on
where the server was installed:
C:\Program Files\Macromedia\Flash Communication Server MX\scriptlib
It could be modified to add a second path, separated from the first one with a semi-
colon (note that line breaks have been introduced for readability):
C:\Program Files\Macromedia\Flash Communication Server MX\scriptlib;
C:\Program Files\Macromedia\Flash Communication Server MX\securitylib
Appending a path in the <ScriptLibPath> tag has a number of advantages. You can
build your own common library of scripts without placing anything in the scriptlib
directory and possibly editing or overwriting the files supplied by Macromedia. By
placing individual Application.xml files in the home directory of individual applica-
tions, you can make libraries available for only those applications. If you want to add
a library for all applications within a virtual host, add a path in the Application.xml
file in the virtual host directory.
Figure 4-8 shows the location of a number of source files for an application named
courseChat. The securitylib directory was created to hold custom scripts that could
be used by any application, and the scripts folder was created to hold scripts just for
the courseChat application.

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.