我正在运行包含移动物体的Flash电影,用于视觉科学实验。我使用眼动追踪设备来监控屏幕上跟随刺激时的眼球运动。 Flash似乎是控制刺激的好选择,因为它允许矢量缩放和平滑刺激运动。
眼动仪使用MATLAB运行。我想将对象的坐标从ActionScript输出到MATLAB,以便在我的最终数据输出中我可以将刺激位置与眼睛位置进行比较。
我知道我可以通过TCP / IP从AS到MATLAB进行通信(虽然实际的程序对我来说很陌生),并且想知道如何提取对象的X和Y坐标(a圈子对象)并将它们发送到MATLAB?
非常感谢任何帮助
答案 0 :(得分:0)
我对MATLAB以及如何为它编程知之甚少,但我会举一个AS3方面的例子。如果您首先要使用TCP / IP通信,则需要定义服务器和客户端。 ServerSocket类仅支持Flash端的AIR应用程序,因此您应决定是制作Flash端服务器还是客户端。如果你想让它成为服务器,你需要写下这样的东西:
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);
}
如果您决定Flash端的客户端连接到您的服务器,请执行以下操作:
var SocketConnection:Socket = new Socket();
SocketConnection.connect(IP_ADDRESS, PORT);
然后你可以使用相同的方法进行书写和阅读。