Advertisement
Guest User

Untitled

a guest
May 24th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var mc = new LoadVars(), _checkinput = 0, sUsername;
  2.  
  3. createTextField("com_txt",this.getNextHighestDepth(),"9","4","532","341");
  4. com_txt.border = true;
  5. com_txt.multiline = true;
  6. com_txt.wordWrap = true;
  7. com_txt.html = true;
  8.  
  9. createTextField("input_txt",this.getNextHighestDepth(),"9","350","532","22");
  10. input_txt.border = true;
  11. input_txt.type = "input";
  12.  
  13. _root.com_txt._visible = false;
  14. _root.input_txt._visible = false;
  15.  
  16. // Sockets
  17. function SocketConnect(ip, port) {
  18.     mc.socket = new XMLSocket();
  19.     mc.socket.connect(ip,port);
  20.    
  21.     mc.socket.onConnect = function(success) {
  22.         if (success) {
  23.             Comtrace("Welcome to the chat, <b>" + sUsername + "</b>!");
  24.             Send(sUsername);
  25.             Send("/users");
  26.             setInterval(SocketRecv, 100);
  27.         }
  28.         else {
  29.             Comtrace("Unsuccessful connection to the server.");
  30.         }
  31.     };
  32.    
  33.     mc.socket.onClose = function() {
  34.         Comtrace("The client has been disconnected");
  35.     };
  36.    
  37.     mc.socket.addEventListener(DataEvent.DATA, SocketRecv);
  38. }
  39.  
  40.     function Send(Data) {
  41.         Data = filtering(Data);
  42.         mc.socket.send(Data);
  43.         Comtrace(sUsername+": "+Data);
  44.     }
  45.    
  46.     function SocketRecv(event:DataEvent):void {
  47.         Send("test");
  48.         mc.socket.onData = function(event.data) {
  49.             Comtrace(event.data);
  50.         };
  51.     }
  52.  
  53. // Utility stuff
  54. function Comtrace(txt) {
  55.     _root.com_txt.htmlText = _root.com_txt.htmlText+txt+"\n";
  56. }
  57.  
  58. var keyListener = new Object();
  59. keyListener.onKeyDown = function() {
  60.     //Enter Key
  61.     if (Key.isDown(Key.ENTER) && _root.input_txt.text != "") {
  62.         Send(_root.input_txt.text);
  63.         _root.input_txt.text = ""; 
  64.     }
  65. };
  66.  
  67. Key.addListener(keyListener);
  68.  
  69. function filtering(raw) {
  70.     var _local3;
  71.     var _local2 = new String(raw);
  72.    
  73.     return _local2.replace(">", ">").replace("<", "<");
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement