1

I can not manage to use a local connection between a master file that's set for AIR and a slave file for FlashPlayer (regular SWF). Here is the code of two test files ...

The master/receiver file :

// test-AIR.fla
import flash.display.Loader;
var loadK1:Loader=new Loader();
loadK1.load(new URLRequest("K1/test-SWF.swf"));
addChild(loadK1);
var localConnection:LocalConnection = new LocalConnection();
localConnection.allowDomain("*");
localConnection.client = this;
localConnection.connect("_connectionName");
function onMethod(timeString:String):void {
    trace("onMethod called at: " + timeString);
    }

The sender ...

// K1/test-SWF.fla
var localConnection:LocalConnection = new LocalConnection();
localConnection.send("_connectionName", "onMethod");
trace("END of test-SWF.swf");

Then, here is the ouput showing that onMethod is not called :

[SWF] test-AIR.swf - 1170 bytes after decompression

K1/test-SWF.swf - 625 bytes after decompression

END of test-SWF.swf[SWF]

I have the feeling I tried everything. Can someone point out what's wrong or what I'm missing ? Thanks,

Shiluba
  • 31
  • 4
  • A couple of wild guesses. 1. Load the external SWF **after** you set the LocalConnection up. Who knows, maybe it loads and executes on spot, before you even connect the receiver. 2. Sign up all the LCs for all the possible events and trace them. Might give you a hint. 3. The **onMethod** method must be **public**, I think. 4. Try it inside one SWF first and make sure it works. 5. Read up the official documentation, there are plenty of nuances: https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/LocalConnection.html#connect() – Organis Sep 18 '18 at 10:28
  • Thank you, I tried everything with no success. I'm afraid that it's due to LocalConnection not being suported for the mobileDevice profile : https://help.adobe.com/en_US/air/build/WS144092a96ffef7cc16ddeea2126bb46b82f-8000.html I'm looking for a workaround. Hints would be greatly appreciated ! – Shiluba Sep 18 '18 at 16:01
  • Why do you at all need LC to communicate within a single application instance? – Organis Sep 18 '18 at 18:09
  • It's a big application that was originally designed for web browsers. Using several files makes it load faster. It's got more than 10 FLA/SWF files total. Now, I'm trying to port it to mobile and desktop devices. – Shiluba Sep 18 '18 at 19:56
  • Take a look at [Flex ModuleLoader](https://flex.apache.org/asdoc/spark/modules/ModuleLoader.html). Depending on your architecture, it might be an option. – Brian Sep 18 '18 at 20:51
  • @Shiluba It is understandable. But that was not the question I asked. LC is a viable option, indeed, if these SWF modules go as separate applications in need to communicate. If they are loaded into the single application, you can communicate directly (addressing the display list hierarchy) or less directly (via some message dispatching class). – Organis Sep 19 '18 at 06:03
  • Thank you both. I may try ModuleLoader. Well thought, though Adobe says : « _Modules are not supported for AIR mobile applications._ » https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/modules/ModuleLoader.html#includeExamplesSummary @Organis The project is to be published for both web-browsers (separate apps), desktop and mobile devices (single app). So we'd like to keep it publishable as separate files for the web-browsers. Can you please be more specific about how to communicate directly by addressing the display list hierarchy ? I think I'm missing something. – Shiluba Sep 19 '18 at 08:32
  • If you load the external SWF and set it so it is in the same SecurityDomain (if you pack all SWFs into one APK, you don't need to do anything), then **parent** of the external SWF is the **Loader** instance, hence **parent.parent** will be the **Loader**'s parent, that if you attached the **Loader** instance to the main SWF's display list. If both SWFs are in the same SecurityDomain, they can access each other's display lists with no restrictions. – Organis Sep 19 '18 at 08:40
  • In this case, communicating directly by addressing the display list hierarchy looks like the proper way to go. Here is what I tried in K1/test-SWF.swf : `var p:MovieClip = this.parent.parent as MovieClip; p.onMethod();` This way, **onMethod** gets called from the child app, whatever the publishing target is. Feel free to clean/improve this code before I post the answer. Thanks again. – Shiluba Sep 19 '18 at 09:28

1 Answers1

2

Since both SWFs are in the same SecurityDomain, they can access each other's display lists with no restrictions. Thus I fixed the issue by calling the method through the display list hierarchy :

MovieClip(this.parent.parent).onMethod();

This way,the method can be called from the child app, whatever the publishing target is (browser, desktop, mobile devices ...).

@Organis thank you for your help!

Shiluba
  • 31
  • 4