Search code examples
actionscript-3airlocalconnection

As3 - LocalConnection between SWF and AIR desktop app


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


Solution

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