Opening a connection to the server

Open a new file in the Flash authoring environment, and then add the client-side ActionScript commands to connect to the server.

To connect to Flash Media Server:

  1. In a new Flash application, begin opening a connection by issuing the following command:
    my_nc = new NetConnection();
    
  2. Follow this command with a connect command:
    my_nc.connect(targetURI);
    

    In this basic syntax for NetConnection.connect() (omitting optional parameters), targetURI is the Uniform Resource Identifier (URI) of an application on the Flash Media Server that should run when the connection is made. To specify targetURI, use one of the following formats (items in brackets are optional):

    rtmp://localhost[:port]/appName[/instanceName] 
    

    The use of localhost indicates that the server is running on your local computer.

    rtmp://host[:port]/appName[/instanceName] 
    

    NOTE

     

    In all syntax examples for targetURI, you must specify rtmp (the Real-Time Messaging Protocol) as the protocol for the connection. If you omit it, Flash Player assumes you want to make an HTTP connection to an application server, and your connection fails.

    To connect to a virtual host other than the default virtual host, specify the virtual host's name in host. If the server is running on your local computer, you can use "localhost" as the host name in the URI; this is often convenient during application development.

For example, the following code uses the new NetConnection constructor to create a new connection object. Then, the object is connected to the server with the call to my_nc.connect().

// Makes a new connection object
my_nc = new NetConnection();
    
/* Connects to the instance named appInstance 
     of the application named appName
     located on the Flash Media Server 
/* that is running on the virtual host myServer.myDomain.com
my_nc.connect("rtmp://myServer.myDomain.com/appName/appInstance");

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/fms/2/docs/00000032.html