我刚刚在flash中启动了一个项目,但是它无法启动XMLSocket。
我的代码:
import Network.CommunicationBootstrap;
var network:CommunicationBootstrap = new CommunicationBootstrap();
network.start("127.0.0.1", 30000);
封装网络类 CommunicationBootstrap:
package Network {
import flash.net.XMLSocket;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
public class CommunicationBootstrap {
private var socket:XMLSocket = new XMLSocket();
public function CommunicationBootstrap() {
socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
}
public function start(ip:String, port:int):void {
this.socket.connect(ip, port);
trace("Testing this out!");
}
private function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
}
}
我的错误是: ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Socket Error. URL: 127.0.0.1"] securityErrorHandler: [SecurityErrorEvent type="securityError" bubbles =false cancelable=false eventPhase=2 text="错误 #2048: 安全沙箱违规:file:///C|/Users/iufrs/Documents/AS3/1/Torn.swf 无法从 127.0.0.1:30000 加载数据。 "]
(通过跟踪和 2 个事件获得)