Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mc = new LoadVars(), _checkinput = 0, sUsername;
- createTextField("com_txt",this.getNextHighestDepth(),"9","4","532","341");
- com_txt.border = true;
- com_txt.multiline = true;
- com_txt.wordWrap = true;
- com_txt.html = true;
- createTextField("input_txt",this.getNextHighestDepth(),"9","350","532","22");
- input_txt.border = true;
- input_txt.type = "input";
- _root.com_txt._visible = false;
- _root.input_txt._visible = false;
- // Sockets
- function SocketConnect(ip, port) {
- mc.socket = new XMLSocket();
- mc.socket.connect(ip,port);
- mc.socket.onConnect = function(success) {
- if (success) {
- Comtrace("Welcome to the chat, <b>" + sUsername + "</b>!");
- Send(sUsername);
- Send("/users");
- setInterval(SocketRecv, 100);
- }
- else {
- Comtrace("Unsuccessful connection to the server.");
- }
- };
- mc.socket.onClose = function() {
- Comtrace("The client has been disconnected");
- };
- mc.socket.addEventListener(DataEvent.DATA, SocketRecv);
- }
- function Send(Data) {
- Data = filtering(Data);
- mc.socket.send(Data);
- Comtrace(sUsername+": "+Data);
- }
- function SocketRecv(event:DataEvent):void {
- Send("test");
- mc.socket.onData = function(event.data) {
- Comtrace(event.data);
- };
- }
- // Utility stuff
- function Comtrace(txt) {
- _root.com_txt.htmlText = _root.com_txt.htmlText+txt+"\n";
- }
- var keyListener = new Object();
- keyListener.onKeyDown = function() {
- //Enter Key
- if (Key.isDown(Key.ENTER) && _root.input_txt.text != "") {
- Send(_root.input_txt.text);
- _root.input_txt.text = "";
- }
- };
- Key.addListener(keyListener);
- function filtering(raw) {
- var _local3;
- var _local2 = new String(raw);
- return _local2.replace(">", ">").replace("<", "<");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement