All pastes #977260 Raw Edit

AS 2.0

public text v1 · immutable
·published 2008-04-08 18:42 UTC
rendered paste body

_root.username = '';
_root.whichclip = '';
_root.htmldir = 'http://86.104.141.8/nowlive/img/emo/';
var myXMLSocket:XMLSocket = new XMLSocket()

function explode(separator:String, string:String) 
{

	var list = new Array();

	if (separator == null) return false;
	if (string == null) return false;

	var currentStringPosition = 0;
	while (currentStringPosition<string.length) {
		var nextIndex = string.indexOf(separator, currentStringPosition);
		if (nextIndex == -1) break;
		var word = string.slice(currentStringPosition, nextIndex);
		list.push(word);
		currentStringPosition = nextIndex+1;
	}
	if (list.length<1) {
		list.push(string);
	} else {
		list.push(string.slice(currentStringPosition, string.length));
	}
	return list;
}

function replaceString(myString:String, replaceThis:String, withThis:String):String {
var split_ar = myString.split(replaceThis)
myString = split_ar.join(withThis)
return myString;
}

function chat(msg)
{
	old_text = _root.chatbox.htmlText;
	newtxt = old_text+"</br>"+msg;	
	// newtxt = replaceString(newtxt, ":)))", '<img src="'+_root.htmldir+'laugh.gif" />');
	_root.chatbox.htmlText = newtxt;

	trace(newtxt);
}

function send_msg()
{
	if(_root.cstatus == 'true')
	{
		myXML = "msg "+_root.new_message.text;
		myXML.contentType = "text";
		_root.myXMLSocket.send(myXML);

		
		_root.chat("<b>&lt;"+_root.username+"&gt;"+_root.new_message.text+'</b>');
		_root.new_message.text = '';
	}
	else
	{
		chat("[ SYSTEM ][ Error: ] <b>Sending Failed! You`re not connected to the Sockets Server!</b>");
	}
}
function get_names()
{
	myXML = "names";
	myXML.contentType = "text";
	_root.myXMLSocket.send(myXML);
	// _root.chat("[ SYSTEM ] Requesting users in channel! ");
}

function login()
{
	myXML = "login "+_root.lusername.text+" "+_root.lpassword.text;
	myXML.contentType = "text";
	_root.myXMLSocket.send(myXML);
	_root.username = _root.lusername.text;

}


_root.myXMLSocket.onConnect = function (success:Boolean) 
{
	if (success) 
	{
		_root.chat("Connection succeeded!")
		_root.cstatus = 'true';
	} 
	else 
	{
		_root.chat("[ SYSTEM ] Connection failed!")
		_root.cstatus = 'false';
	} 
}
if (!_root.myXMLSocket.connect('86.104.140.141', 10000)) 
{
	_root.chat("[ SYSTEM ] Connection failed!")
	_root.cstatus = 'false';
}		



myXMLSocket.onXML = function (doc) 
{
			
	doc.ignoreWhite = true;
	trace('received \n --- \n '+doc+"\n ----- \n");
	var i=0;
	for (var aNode:XMLNode = doc.firstChild; aNode != null; aNode = aNode.nextSibling,i++) 
	{			
		if (aNode.nodeName == "msg" and aNode.attributes.user) 
		{
			
			trace('received message from other client');
			_root.chat("&lt;"+aNode.attributes.user+"&gt;"+aNode.attributes['text']);
		}
		if(aNode.nodeName == "users")
		{
			if(i==0)
			{
				_root.user_list.removeAll();
				_root.user_list.addItem (aNode.attributes['uname'],aNode.attributes['uid']); 				
			}
			else
			{
				_root.user_list.addItem (aNode.attributes['uname'],aNode.attributes['uid']); 
			}
			
		}
		if (aNode.nodeName == "system")
		{
			msg = aNode.attributes.msg;
			trace('system message:'+msg);
			if(msg == "Login Failed!")
			{
				chat("[ SYSTEM ] Login Failed!")
			}
			else if(msg == 'Login Ok!')
			{
				chat("[ SYSTEM ] Logged in!")
				_root.gotoAndStop(3);
			}
					
		}
		else
		{
			trace(aNode);
		}
	}
}