Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 ActionScript向MATLAB报告对象坐标_Actionscript 3_Sockets_Matlab - Fatal编程技术网

Actionscript 3 ActionScript向MATLAB报告对象坐标

Actionscript 3 ActionScript向MATLAB报告对象坐标,actionscript-3,sockets,matlab,Actionscript 3,Sockets,Matlab,我正在运行一部包含移动物体的Flash电影,用于视觉科学实验。我用一个眼球跟踪装置来监测在屏幕上跟踪刺激时的眼球运动。Flash似乎是控制我的刺激的一个很好的选择,因为它允许向量缩放和平滑的刺激运动 眼动跟踪器正在使用MATLAB运行。我想将对象的坐标从ActionScript输出到MATLAB,以便在最终的数据输出中比较刺激位置和眼睛位置 我知道我可能能够通过TCP/IP从AS到MATLAB进行通信(尽管实际过程对我来说是陌生的),我想知道如何提取对象(圆形对象)的X和Y坐标并将其发送到MAT

我正在运行一部包含移动物体的Flash电影,用于视觉科学实验。我用一个眼球跟踪装置来监测在屏幕上跟踪刺激时的眼球运动。Flash似乎是控制我的刺激的一个很好的选择,因为它允许向量缩放和平滑的刺激运动

眼动跟踪器正在使用MATLAB运行。我想将对象的坐标从ActionScript输出到MATLAB,以便在最终的数据输出中比较刺激位置和眼睛位置

我知道我可能能够通过TCP/IP从AS到MATLAB进行通信(尽管实际过程对我来说是陌生的),我想知道如何提取对象(圆形对象)的X和Y坐标并将其发送到MATLAB


任何帮助都将不胜感激

我不太了解MATLAB以及如何为其编程,但我将在AS3方面给您举个例子。如果要使用TCP/IP通信,首先需要定义服务器和客户端。ServerSocket类仅支持闪存端的AIR应用程序,因此您应该决定是使用闪存端服务器还是客户端。如果您希望它成为服务器,则需要编写如下内容:

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); 
}
var SocketConnection:Socket = new Socket();
SocketConnection.connect(IP_ADDRESS, PORT);
如果您决定将客户端连接到您的服务器,请如下所示:

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); 
}
var SocketConnection:Socket = new Socket();
SocketConnection.connect(IP_ADDRESS, PORT);

然后,您可以使用相同的书写和阅读方法进行通信。

您需要在两者之间进行实时通信,还是在实验结束后离线比较坐标?为了回答您的问题,有多种方法可以在MATLAB中使用TCP/IP通信。请参阅本文以了解概述,这是一个在MatlabAmro中使用Java功能的示例。我需要实时沟通。