• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 3. Managing Connections > Reusing a NetConnection Object

3.3. Reusing a NetConnection Object

Often a Flash movie must connect to more than one application instance. A familiar example is when Flash must first connect to a lobby so the user can select a chat room to visit. In this case, the lobby may be one application and the chat rooms may be implemented by another application. The lobby connection can be closed and then a new NetConnection object, with a different onStatus( ) method, can be created to connect to the chat application. Instead of creating a new NetConnection object, the Flash movie can reuse an existing one. In theory, you can disconnect from one application and connect to another by calling the connect( ) method with a new target URI. When this happens, the old connection is closed and a new one is attempted. However, two other things should normally happen. First, before a connection is closed, you should perform any required cleanup, such as closing objects and components that depend on the connection. Second, you must perform any preparatory work—at minimum you'll usually put in place a different onStatus( ) handler—before connecting to the next application.

To follow through with the previous example, suppose an additional application, named testChat, is available and that once the user is in the lobby he can click a button to visit a testChat instance named room1. In this case, the main timeline of the movie would require separate Login, Lobby, and ChatRoom frames as illustrated in Figure 3-2.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint