This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
78
Chapter 3
CHAPTER 3
Managing Connections
Before a Flash movie can exchange audio, video, and other data with a FlashCom
Server application, it must request a network connection to the server. If an applica-
tion instance on the server accepts the connection request, a TCP connection is made
available to both the movie and application instance to use for ongoing communica-
tions. We saw in the preceding chapter that the SimpleConnect component can cre-
ate a connection. This chapter covers connections in more depth, including how to
write custom code to handle various changes in the connection status as well as dif-
ferent error types.
A network connection can be managed within a Flash movie using a NetConnection
object. This object’s methods are used to request, close, and monitor the status of a
network connection. The SharedObject and NetStream classes, as well as Macrome-
dia’s communication components, all depend on access to a NetConnection object in
order to communicate with the FlashCom Server.
Making a Connection
NetConnection objects are created by calling the NetConnection( ) constructor func-
tion:
lobby_nc = new NetConnection( );
In this example, the lobby_nc variable stores a NetConnection object, which can be
used to attempt to connect to an application instance:
if (lobby_nc.connect("rtmp:/testLobby", userName, password)) {
trace("Attempting connection...");
}
else {
trace("Can't attempt connection. Is the URI correct?");
}
In this example, the URI rtmp:/testLobby is the address of an instance of an applica-
tion named testLobby that resides on the server from which the movie was
downloaded. The connect( ) method is always passed the URI of the 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.