AS3 - LocalConnection between AIR master & SWF sender

230 views Asked by At

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,

1

There are 1 answers

0
Shiluba On BEST ANSWER

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!