Flash错误:SecurityError:关于套接字的错误#2000

时间:2012-11-25 10:58:44

标签: actionscript-3 flash sockets

function SocketExample() 
{
   socket = new Socket();

   // Add an event listener to be notified when the connection
   // is made
   socket.addEventListener( Event.CONNECT, onConnect );

   // Connect to the server
   socket.connect( "127.0.0.1", 2901 );
}

function onConnect( event:Event ):void 
{
  tt.text = "Successful linking";
}

我尝试通过Flash as3.0连接到Socket。 但它不起作用,它向我显示错误“SecurityError:Error#2000”。 如何避免此错误?

1 个答案:

答案 0 :(得分:0)

尝试将调用移到构造函数之外的connect()方法并稍后调用它。

This article提到导致此错误的一个原因是,在Flash有机会设置它的“安全上下文”之前,您尝试执行某些操作。

例如,您可以使用setInterval()方法或Timer对象在启动后几(或几百)毫秒连接套接字。或者您可以在屏幕上添加一个按钮,仅在单击按钮后才能连接。