
Chapter 3 40
4 Create the event handler for the Connect button. If the user selected the button when the label
was Connect, then connect to the server. If the button label is Disconnect, close the
connection.
// Event handler for Connect_Btn
function doConnect() {
// If user wants to connect...
if (Connect_btn.getLabel() == "Connect") {
// Connect to the chat application
client_nc.connect("rtmp:/doc_hello/room_01", User.text);
// Update button label
Connect_btn.setLabel("Disconnect");
// If user wants to disconnect...
} else if (Connect_btn.getLabel() == "Disconnect") {
// Close connection
client_nc.close();
// Reset button label
Connect_btn.setLabel("Connect");
// Reset the text fields
user.text = "";
message.text = "";
}
}
5
Write the function the server will call to return the message to the client.
// Callback function server calls to send message back to
// this client.
client_nc.msgFromSrvr = function(msg) {
var msg;
_root.Message.text = msg;
}
Commentaires sur ces manuels