As3 - SWF和AIR桌面应用程序之间的LocalConnection

时间:2013-01-09 12:05:30

标签: actionscript-3 air localconnection

我需要从嵌入式SWF(Web浏览器)向基于AIR的桌面应用程序发送文本。 我完成了documentation中解释的所有内容,但我无法建立连接。

有人看到我做错了什么或者能指出一个有效的例子吗?

来自SWF:

function startConnection(e:Event=null):void
{
var localConnection:LocalConnection 
localConnection = new LocalConnection(); 

localConnection.client = this; 
localConnection.allowDomain("app#com.example.desktop"); 

var textToSend = "Hello world! Source: http://www.foobar.com";
localConnection.send("app#com.example.desktop:connectionName", "methodName",textToSend); 
} 

从AIR桌面应用程序:

 function onBrowserInvoke (event:BrowserInvokeEvent):void{
    var localConnection:LocalConnection 
    localConnection = new LocalConnection(); 
    localConnection.client = this

    localConnection.allowDomain("example.com");
    localConnection.connect("connectionName");
    } 

谢谢。 乌利

1 个答案:

答案 0 :(得分:2)

工作代码是:

AIR:
    var localConnection:LocalConnection = new LocalConnection();
    localConnection.send("_myConnection", "methodName", "Hello world! Source: http://www.foobar.com"); 
SWF:
    var localConnection:LocalConnection = new LocalConnection();
    localConnection.allowDomain("app#airtest"); //or use "*" wildcard to allow any domains and AIR applications
    localConnection.client = this;
    localConnection.connect("_myConne‌​ction");

其中airtest是AIR应用程序的应用程序ID。在本地连接名称之前使用_符号来支持不可预测的域名(它将在调试模式和http中工作)。