As3 - LocalConnection between SWF and AIR desktop app

扶醉桌前 提交于 2019-11-28 06:21:09

问题


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?

From the 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); 
} 

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");
    } 

Thank you. Uli


回答1:


The working code is:

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");

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).



来源:https://stackoverflow.com/questions/14234833/as3-localconnection-between-swf-and-air-desktop-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!