ActionScript Connect and Connect UI Components

When you do not plan to use the SimpleConnect UI component, use these scripts in Listings E.1 and E.2 on the client and on the server to make your connection work with other UI components.

Listing E.1 Flash ActionScript
// instantiate the NetConnection Object
nc = new NetConnection();
// create an onStatus Handler for nc
nc.onStatus = function(info) {
      trace("LEVEL: "+info.level+"  CODE: "+info.code);
      if (info.code == "NetConnection.Connect.Success") {
            // ** place your code here to execute when the server accepts **
      }
};

// make a connection request (invoke the application.onConnect)
// pass two additional parameters to the onConnect method (userName, Password)
nc.connect("rtmp://myApplication/myInstance", "Tracey Davis", "Bert");

// Connect any UI Components to the connection
peopleList_mc.connect(nc);
connectionLight_mc.connect(nc);
chat_mc.connect(mc);
Listing E.2 Server-Side ActionScript (main.asc)
// Load the Flash UI component server-side objects
load("components.asc");

// Listen for the new connection to this application.
// userName is a parameter passed in from the client-side nc.connect call.

application.onConnect =function(newClient,userName,password)
{
      // Set the global user name for the UI Components
      // with the user name passed into this function.
      gFrameworkFC.getClientGlobals(newClient).username =newUserName;

      // Accept the connection from the user,
      // This line will invoke the NetConnection onStatus handler
      application.acceptConnection(newClient);

      // Trace Output that will appear in the App Inspector
      trace("hello There," + userName);
      trace("A Flash Client was just connected");
}


    Part I: 10 Quick Steps for Getting Started