# onData and an obnoxious String

**URL:** <https://forum.kirupa.com/t/ondata-and-an-obnoxious-string/170477>\
**Category:** flash\
**Created:** [November 26, 2005, 3:29pm UTC](https://forum.kirupa.com/t/ondata-and-an-obnoxious-string/170477 "2005-11-26T15:29:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Favardin](https://avatars.discourse-cdn.com/v4/letter/f/f08c70/32.png) [@Favardin](https://forum.kirupa.com/u/Favardin)\
**Post date:** [November 26, 2005, 3:29pm UTC](https://forum.kirupa.com/t/ondata-and-an-obnoxious-string/170477/1 "2005-11-26T15:29:43Z")

</div>

Very well… I don’t really know what’s wrong with this.  
The Server connection works just fine, but the databuffer always appears to be empty if I try to access it (either directly or with a get-function).

If I trace databuffer in the onSocketData-function it returns the right value (that is a string from the server, like "|25| " terminated by the NULL-Character).

Any idea anyone?

```auto

class MySocket extends MovieClip
{
	var socket:XMLSocket;
	var port:Number;
	var databuffer:String;
	
	function MySocket(__port:Number)
	{
		socket = new XMLSocket();
		
		port = __port;

		if (!socket.connect("localhost", port)) 
				trace ("Connection failed!");
			
		socket.onConnect = onSocketConnect;	
		socket.onData = onSocketData;
		
		databuffer = new String();

		setInterval(this.request, 24, this.socket);
	}

	private function onSocketData(data:Object)
	{
	  var s:String = new String(String(data));
		databuffer = s.substring(0);
		trace(databuffer);
	}

	private function onSocketConnect(success:Boolean)
	{
		if (success)
			trace ("Connection succeeded!");
		else 
			trace ("Connection failed!");
	}
	
	/* request data function */
	
	function request(__socket:XMLSocket)
	{
		__socket.send("
");	
	}
}

```
