Skip to main content
Participant
Aug 28, 2017 6:16 PM UTC
Question

How do I communicate between an AIR application and a Flex application loaded through an HTMLLoader in AIR?

I have been trying to use LocalConnection, however I am getting an invalid argument error, so Im questioning whether or not this LocalConnection approach is even right:

AIR Application:

public function init() {

                var conn:LocalConnection;

                conn = new LocalConnection();

                conn.allowDomain("localhost");

                conn.connect("connection1");

                loadHTML();

}

private function loadHTML() {

                var urlReq:URLRequest = new URLRequest("http://localhost/myapp/");

                htmlUI.htmlLoader.load(urlReq);   

                visible=true;        

                //set attribute to allow external links to open in default system browser

                htmlUI.htmlLoader.navigateInSystemBrowser = true;

}

public function connect():void {

                trace("LOCAL CONNECTION SUCCEEDED");

}

FLEX Application:

private function doSomethingOnClick() : void {

    var conn:LocalConnection;

    conn = new LocalConnection();

    try {

        conn.send('app#MyAirApplication:connection1', 'connect');

    } catch (error:ArgumentError) {

        TIAlert.error(error.getStackTrace())

    }

}

This topic is closed to new replies. Start a new post to keep the conversation going.

6 replies

itlancer
Inspiring
Aug 31, 2017 11:32 AM UTC

I have the similar task to communicate between different SWF files. And we are suffering from ArgumentError bug:

Tracker

ArgumentError: Error #2082: Connect failed because the object is already connected.

May be this is your case too.

Translate
jt_sweAuthor
Participant
Aug 31, 2017 7:45 PM UTC

Thanks!

Translate
Inspiring
Aug 30, 2017 12:23 PM UTC

RTFM LocalConnection

it's all here in the doc, in short you don't define a client for the function callback

Translate
jt_sweAuthor
Participant
Aug 30, 2017 7:04 PM UTC

I have it running when loading my Flex application through a local webserver, however when it's loaded in a server on a different machine the local connection doesn't seem to go through.

I understand that LocalConnection only works when the swf files are on the same machine, but shouldn't the AIR's HTMLLoader load the Flex application's swf file locally, and thus LocalConnection should work?

Translate
Inspiring
Aug 31, 2017 5:13 PM UTC

it can not work because you don't define a client for your LocalConnection

conn = new LocalConnection();

conn.client = ???

and so that can not work

conn.send('app#MyAirApplication:connection1', 'connect');

if you read the doc everything about the client part is explained

so let's be clear, when it does not work it's not because there is some issues with the API itself
it's because you are not following the doc to use it and/or your code sample is not really the one you are testing with

good luck

Translate