Table of Contents

LocalConnection.connect( ) Method Flash 6

open a named connection
receiveConn.connect(connectionName)

Arguments

connectionName

A string name for the connection.

Returns

A Boolean�true if the connection opened successfully, false if the operation failed (for example, if a connection named connectionName already exists in any Player or if receiveConn already has an open connection).

Description

The connect( ) method is used by a receiving LocalConnection object to open a connection, thus enabling future senders to invoke its methods. All methods should be defined before connect( ) is invoked. For example, the following code creates a LocalConnection object, then defines its methods, then opens a connection named "channel3" (making displayMsg( ) eligible for remote execution):

receiveConn = new LocalConnection();
receiveConn.displayMsg = function (msg) {
  output_txt.text += msg + "\n";
}
receiveConn.connect("channel3");

By checking the return value of connect( ), we can respond gracefully to connection attempt failures. For example:

connectSuccess = receiveConn.connect("channel3");
if (connectSuccess) {
  // ...proceed with application
} else {
  // ...display failure screen
}

When connectionName does not start with an underscore ( _ ), the name specified is automatically prefixed with receiveConn's subdomain and a colon (e.g., "channel3" becomes "oreilly.com:channel3" if the movie is posted at www.oreilly.com). When connectionName starts with an underscore, no prefix is applied.

Senders invoking remote methods on receiveConn must match the final connection name (automatic prefix + connectionName) when invoking send( ). See LocalConnection.allowDomain( ) and LocalConnection.send( ) for a discussion of connection name matching.

A LocalConnection object can maintain only one open connection at a time and cannot open a connection with a connection name that is already in use. To close an open connection, use LocalConnection.close( ).

See Also

LocalConnection.allowDomain( ), LocalConnection.close( ), LocalConnection.send( )


Table of Contents