Skip to main content
Participant
August 28, 2017
Question

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

  • August 28, 2017
  • 2 replies
  • 595 views

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 has been closed for replies.

2 replies

itlancer
Inspiring
August 31, 2017

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.

jt_sweAuthor
Participant
August 31, 2017

Thanks!

Inspiring
August 30, 2017

RTFM LocalConnection

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

jt_sweAuthor
Participant
August 30, 2017

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?

Inspiring
August 31, 2017

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