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

2023-09-08 12:41:44 作者:眼泪成海却未蓝

我需要到从嵌入的SWF(网页浏览器)文本到基于AIR的桌面应用程序。 我所做的一切都像在文档但我无法建立连接。

I need to send a text from an embedded SWF (Web browser) to an AIR based desktop app. I did everything like explained in the documentation but I can't establish a connection.

是否有人看到我做错了什么,也可以点我一个工作的例子?

Does anybody see what I did wrong or can point me to a working example?

从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桌面应用程序:

From the AIR desktop app:

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

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

感谢您。 乌利

推荐答案

工作code是:

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 是应用程序ID的AIR应用程序。使用 _ 符号本地连接名称之前为支持联合国predictable域名(它会工作在调试模式,并通过HTTP)。

Where airtest is the app id for AIR application. Use the _ symbol before local connection name for supporting unpredictable domain names (it'll work in debug mode and via http).