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
|
129
The onConnect( ) handler in Example 4-2 allows the client to connect to the applica-
tion instance by invoking application.acceptConnection( ). Client connection requests
can also be rejected using application.rejectConnection( ). Calling these methods
inside onConnect( ) is not really necessary. If onConnect( ) returns
true, the client
connection is accepted; the connection is rejected if onConnect( ) returns
false. More
importantly, if onConnect( ) returns nothing or
null, the client is left in a pending
state and is unable to communicate with the server. Connections for pending clients
can still be accepted or rejected outside of the onConnect( ) method by calling appli-
cation.acceptConnection( ) or application.rejectConnection( ).
If the application.onConnect( ) method is not defined, all client connec-
tions are accepted and all clients are given global read and write access
equivalent to setting
readAccess and writeAccess to “/”.
application.onDisconnect( )
The application.onDisconnect( ) method is called when FlashCom detects that a cli-
ent with an accepted or pending connection has disconnected from the instance. In
the example, the
client.userName property is used to identify who is leaving.
application.onAppStop( )
Finally, application.onAppStop( ) is called just before the instance is shut down. It is
passed an information object that specifies the reason for the shutdown; it can pre-
vent the instance from shutting down by returning
false.
Using the App Inspector to Run Scripts
To try out a script like the one in Example 4-2, create a text file named main.asc (or
download it from the book’s web site) and save it into a subdirectory of your applica-
tions folder named helloWorld. Find the app_inspector.swf movie (located in Flash-
Com 1.5’s flashcom_help/html/admin directory). This .swf is a testing tool known as
the App Inspector.
Start the app_inspector.swf movie by opening it in the Flash Player, or load the app_
inspector.html page into your browser and enter the location of the server in the Host
field. If you are running FlashCom on your workstation, enter
localhost in the Host
field. If FlashCom is running on a remote server, enter the server’s IP address or host-
name. In the Name and Password fields, enter the administrator’s username and
password, which you chose during FlashCom’s installation procedure.
After connecting, enter
helloWorld in the App/Inst field and click the Load button, as
shown in Figure 4-3. If the instance doesn’t load, an information icon should appear
near the Load button. Click on it to see what went wrong, fix and resave your script
if necessary, and try again.
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
130
|
Chapter 4: Applications, Instances, and Server-Side ActionScript
If the helloWorld/_definst_ instance is not loaded successfully, click on the View
Detail button, as shown in Figure 4-4.
If the
helloWorld/_definst_ instance is loaded successfully, click on the Live Log tab
of the App Inspector. Click the Reload App button to force the instance to restart so
that you can see the output from the test script’s application.onAppStart( ) method.
Figure 4-5 shows the output in the Live Log area of the App Inspector after the hel-
loWorld application was restarted.
The log shows the application instance was shut down and restarted, but the mes-
sages do not appear in the order you might expect. System messages and trace( )
messages from the script are often intermixed. For example, the system message
“Loading of app instance: helloWorld/_definst_ successful” appears in between mes-
sages generated by the trace( ) function while the instance was unloading in the
onAppStop( ) method. The messages generated by the script in the previous output
listing occur only in the onAppStart( ) and onAppStop( ) methods. To see messages
Figure 4-3. Loading an application in the App Inspector following login
Figure 4-4. The App Inspector after loading a helloWorld application

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.