
Sample Applications 43
3 Provide a value for the maximum scrolling of the History text box component.
// Set maximum scroll
History.maxscroll = 1000;
4
Prevent the user from sending until after the user has connected to the server.
// Don’t allow the user to send until after connection
_root.Send_btn.setEnabled(false);
5
Create a new network connection.
// Open a connection to the server
client_nc = new NetConnection();
6
Provide an onStatus function to handle any status messages.
// If connection is closed, clear the History and the list
client_nc.onStatus = function(info) {
trace("Level: " + info.level + " Code: " + info.code);
if (info.description == "NetConnection.Connect.Closed") {
History.text = "";
_root.People.removeAll();
}
}
7
Create the event handler for the Connect button. If the user selected the button when the label
was Connect, then connect to the server and update the buttons.
function doConnect() {
if (Connect_btn.getLabel() == "Connect") {
// Connect to the chat application.
// The second parameter, _root.Room.text,
// is the application instance.
_root.client_nc.connect("rtmp:/doc_textchat/" + _root.Room.text,
_root.User.text);
// Update button label
Connect_btn.setLabel("Disconnect");
// Enable send button
_root.Send_btn.setEnabled(true);
8
In the same doConnect function, create a remote shared object and connect to it.
// Create a remote shared object to keep track
// of the users. The value client_nc.uri is the URI of the
// NetConnection the shared object will use to connect to the
// server. I.e., the one just created.
users_so = SharedObject.getRemote("users_so", _root.client_nc.uri,
false);
// Attach the shared object to client_nc
users_so.connect(_root.client_nc);
Commentaires sur ces manuels