PDA

View Full Version : Socket


deadlyAlive
06-04-2010, 01:12 AM
I will be receiving message in the format - "code,message". Example "10, message". I am trying to seperate them based on the code so that, whenever i call the method, code3() i should be getting the relevant message. But when i alert the method, code3() i am getting blank. However when i try alert in progressEvent i am getting the correct value.

package Classes
{

import flash.events.ProgressEvent;
import flash.net.Socket;

import mx.controls.Alert;


public class Sock
{
public var access_all:String;
public var socket:Socket = new Socket();

public function Sock()
{
socket.connect("localhost", 1234);

socket.writeUTFBytes("2\n");
socket.flush();

socket.addEventListener(ProgressEvent.SOCKET_DATA, progressEvent);
}


public function progressEvent(event:ProgressEvent):void
{
var data:String = socket.readUTFBytes(socket.bytesAvailable);
var a:array = data.split(",");

if(data[0] == "3")
{
this.access_all = data[1];
// Alert.show(this.access_all); //correctly alerting
}
}

public function code3():void
{
Alert.show(this.access_all); //alerting blank
}
}
}