2010-04-22 137 views
0

我寫了嘗試連接到端口8787 代碼監聽本地Java服務器的ActionScript客戶端程序如下:連接到Java服務器的問題

import flash.display.*; 
import flash.events.*; 
import flash.net.Socket; 
import flash.system.Security; 

public class Main extends Sprite { 

    // Properties 

    private var socket:Socket; 

    // Constructor 

    public function Main() { 

     Security.loadPolicyFile("xmlsocket://localhost:8787"); 
     socket = new Socket();   
     socket.addEventListener(Event.CONNECT, onConnectHandler); 

     socket.connect("192.168.0.3", 8787); 

    } 

    // Methods 

    private function onConnectHandler(event:Event):void { 

     trace("The socket is now connected..."); 
     var myspr:Sprite = new Sprite(); 
     myspr.graphics.beginFill(0x000000); 
     myspr.graphics.drawCircle(50, 50, 60); 
     myspr.graphics.endFill(); 
     addChild(myspr); 

    } 

} 

但在閃光CS4 IDE我得到以下信息:

Error #2044: Unhandled IOErrorEvent:. text=Error #2031: Socket Error. at Main()

而當我在Firefox下降瑞士法郎我得到:

SecurityError: Error #2010: Local-with-filesystem SWF files are not permitted to use sockets. at flash.net::Socket/internalConnect() at flash.net::Socket/connect() at Main()

注意:而不是「192.168.0.3」,我也測試127.0.0.1和本地主機沒有成功。

回答

0

在本地開發,您需要將SWF添加到Flash的全局安全設置權限:

Flash Settings Manager

添加本地的SWF的位置信任文件列表,並將其設置爲「總是允許。 「