0

I'm running a Flash movie containing a moving object, used for a vision science experiment. I'm using an eye tracking device to monitor the eye movements made when following the stimulus on screen. Flash seems like a good option for controlling my stimulus as it allows vector scaling and smooth stimulus motion.

The eye tracker is running using MATLAB. I'd like to output the co-ordinates of the object from ActionScript to MATLAB so that in my final data output I can compare the stimulus position to eye position.

I understand that I may be able to communicate from AS to MATLAB via TCP/IP (although the actual procedure is alien to me), and wonder how I would go about extracting X and Y co-ordinates of an object (a circle object) and sending them to MATLAB?

Any help would be greatly appreciated

Amro
  • 123,847
  • 25
  • 243
  • 454
CaptainProg
  • 5,610
  • 23
  • 71
  • 116
  • do you need to communicate between the two in real-time, or are you just comparing the coordinates offline after the experiment? – Amro Jul 04 '12 at 11:00
  • 1
    To answer your question, there a number of ways to use TCP/IP communication in MATLAB. See this [post](http://stackoverflow.com/a/7626998/97160) for an overview, and [here](http://stackoverflow.com/a/2677627/97160) is an example of using Java capabilities in MATLAB – Amro Jul 04 '12 at 11:36
  • Thanks Amro. I need to communicate in real time. – CaptainProg Jul 04 '12 at 14:22

1 Answers1

0

I don't know much about MATLAB and how to program for it but I'll give you an example on the AS3 side. If you want to use the TCP/IP communication first of all you'll need to define a server and a client. ServerSocket class is only supported for AIR applicaitons on the Flash side so you should decide whether to make Flash side server or client. In case you want it to be server you'll need to write something like this:

const IP_ADDRESS:String = "127.0.0.1"; //for local hosting
const PORT:uint = 3444; //basically, you can take any port you want, but higher would be better so that it won't have issues with other programs using ports.

var OurServerSocket:ServerSocket = new ServerSocket();
var ConnectedSocket:Socket;
OurServerSocket.addEventListener(ServerSocketConnectEvent.CONNECT, HandleSocketConnection); //adding listener for socket connections, that we'll handle in our method.
OurServerSocket.bind(PORT, IP_ADRESS); //just binding our socket to the IP and port that we defined 
OurServerSocket.listen();

function HandleSocketConnection(e:ServerSocketConnectEvent):void
{
    ConnectedSocket = e.socket; //just saving connected socket instance
    ConnectedSocket.addEventListener(ProgressEvent.SOCKET_DATA, HandleSocketData); //adding listener to handle any data that comes through our connected socket
    trace("Connected: " + ConnectedSocket.remoteAddress);
}

function HandleSocketData(e:ProgressEvent):void
{
    var socket:Socket = e.target as Socket;
    var bytes:ByteArray = new ByteArray();
    socket.readBytes(bytes,0,0);
    var Data:String = bytes.toString(); //when the data comes in we store it in this string so that you can than manipulate easily
}

//use this function to send data through the connected socket
function WriteToSocket(data:String):void
{
    var dataArray:ByteArray = new ByteArray();
    dataArray.writeMultiByte(data, "utf-8");
    ConnectedSocket.writeBytes(dataArray); 
}

If you'll decide client for the Flash side connect to your server like this:

var SocketConnection:Socket = new Socket();
SocketConnection.connect(IP_ADDRESS, PORT);

Then you can communicate using the same methods for writing and reading.

Gio
  • 1,954
  • 3
  • 22
  • 42