Copy link to clipboard
Copied
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())
}
}
Copy link to clipboard
Copied
RTFM LocalConnection
it's all here in the doc, in short you don't define a client for the function callback
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I said I have it running when loading my Flex application through a local webserver, meaning I have that part down already. Relax.
Copy link to clipboard
Copied
I have the similar task to communicate between different SWF files. And we are suffering from ArgumentError bug:
ArgumentError: Error #2082: Connect failed because the object is already connected.
May be this is your case too.
Copy link to clipboard
Copied
Thanks!