
XMLSocket Class
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
955
Example R-11 demonstrates the use of SocketController with a simple chat application.
};
/*
* Callback invoked when server kills the connection.
*/
SocketController.prototype.onClose = function () {
trace("The server has terminated the connection.");
// Invoke the user-defined callback for server disconnect
this.onServerKillConnect();
};
/*
* Closes the connection to the server manually.
*/
SocketController.prototype.killConnect = function () {
trace("Closing current connection.");
this.close();
// Invoke the user-defined callback for client disconnect
this.onClientKillConnect();
};
Example R-11. A simple SocketController chat app
// A Simple Chat App
// Load SocketController class
#include "SocketController.as"
// Start the show
main();
// The chat application
function main () {
// Store a portable reference to the current timeline
_global.chatMain = this;
// Create sending text field
chatMain.createTextField("send_txt", 1, 100, 100, 300, 20);
chatMain.send_txt.border = true;
chatMain.send_txt.type = "input";
// Create output text field
chatMain.createTextField("output_txt", 2, 100, 130, 300, 200);
chatMain.output_txt.border = true;
chatMain.output_txt.type = "dynamic";
// Create the SocketController instance and connect to the server ...