This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
84
|
Chapter 3: Managing Connections
info.level: status
info.code: NetConnection.Connect.Success
info.description: Connection succeeded.
On the other hand, the connection might fail. Possible reasons for failure include
that there is no testLobby application on the server or the server could not be found.
In these cases, the handler reports an “error” status in the
level property and addi-
tional status information is available in the
code property of the information object
(
description is empty in this case):
Attempting connection...
this.isConnected: false
info.level: error
info.code: NetConnection.Connect.Failed
info.description:
The application instance can also refuse the connection request (for example, if the
userName or password values are not acceptable). If the connection is rejected, the
onStatus( ) method is called twice—first with an error message and later with a sta-
tus update. Note the values of the
info object’s level and code properties in each
case:
Attempting connection...
this.isConnected: false
info.level: error
info.code: NetConnection.Connect.Rejected
info.description: Connection failed.
info.application.message: This application has refused your connection.
this.isConnected: false
info.level: status
info.code: NetConnection.Connect.Closed
info.description:
When an application instance rejects the connection attempt, it may return an object
with additional information. If so, the object arrives as an
application attribute of
the
info object passed into the onStatus( ) method. To use the application object,
you need to either know its properties in advance or loop through its properties with
a for-in loop as shown in Example 3-1. If you know the properties that the designer
of the application script uses, they can be accessed without a for-in loop. For exam-
ple, a property named
message can be accessed this way:
if (info.application) {
trace("info.application.message: " + info.application.message);
}
Managing a Connection
After a successful connection is made, it can be broken by various occurrences. A
well-scripted Flash movie monitors the network status and takes appropriate action
as changes occur. This is easily done inside your NetConnection.onStatus( ) handler,

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.