AS3 - LocalConnection 似乎不起作用

AS3 - LocalConnection Doesn't Seem to Work

我正在尝试使用 LocalConnection 在加载到单独浏览器 windows 中的三个 swf 之间建立通信(全部由最初打开的页面打开)。我是 swf 间通信的新手,正在按照 here.

中的教程进行操作

我 运行 这些来自 xampp 服务器进行测试。

基本上,我有 3 个 swf。我有一个 'master' 瑞士法郎和两个 'slave' 瑞士法郎。当启动主 swf 时,它会在新 windows 中打开其他两个 swf。当在主人中点击一个按钮时,我试图只更新其中一个奴隶中的一些文本。后面会发生更复杂的事情,我只是想先弄清楚 LocalConnections。

'master.swf'中的代码(时间线上):

import flash.net.URLRequest;
import flash.events.Event;

//Used as a flag to open each slave window, one of the first frame, one on the second frame, as using navigateToURL twice in a row doesn't seem to work.
var frameCount = 0;

//This is what I'm attempting to send over the LocalConnection.
var messageText = "it worked!";

var slave1url:URLRequest = new URLRequest("slave1.html");
var slave2url:URLRequest = new URLRequest("slave2.html");

//Creates a one-way connection to communicate with JUST slave1
var slave1OutboundConnection:LocalConnection = new LocalConnection();

this.addEventListener(Event.ENTER_FRAME, Update);

slave1Button.addEventListener(MouseEvent.CLICK, SendMessageToSlave1);
slave1Button.buttonMode = true;

//Send a message to slave1 via the slave1OutboundConnection
function SendMessageToSlave1(e:Event){  
    slave1OutboundConnection.send("masterToSlave1Connection", "UpdateTextFromCommunication", messageText);  
}

function Update(e:Event){

    //Open the slave1 page on the first frame, and the slave2 page on the second frame.
    if(frameCount == 0){
        navigateToURL(slave1url, "_blank");
        frameCount++;
    } else if (frameCount == 1){
        navigateToURL(slave2url, "_blank"); 
        frameCount++;
    }   

}

在slave1中:

var masterInboundConnection:LocalConnection = new LocalConnection();

masterInboundConnection.allowDomain("*");

masterInboundConnection.connect("masterToSlave1Connection");

function UpdateTextFromCommunication(receivedArguments){
   displayText.text = receivedArguments;
}

我在每个 html 页面中也有一些自定义 javascript 来设置页面大小和位置,但我认为这无关紧要:

<script>
        //Get the width of the user's monitor
        var resolutionWidth = window.screen.availWidth;

        //Get the height of the user's monitor (minus the height of the task bar)
        var resolutionHeight = window.screen.availHeight;   

        //First screen is 0, second is 1, third is 2, etc.
        var screenNumber = 2;

        //If this screen is not displayed on the primary monitor, add 40 pixels for the lack of the taskbar on other monitors
        if(screenNumber > 0){
            resolutionHeight += 40;
        }

        //Maximize the window
        this.resizeTo(resolutionWidth, resolutionHeight);

        //Move the window to the appropriate display
        this.moveTo(resolutionWidth * screenNumber, 0);         
    </script>

当我点击应该触发通信的按钮时,似乎没有任何反应。

我 运行 html 页面包含 Windows 上本地主机 xampp 服务器上的 IE11 中的这些 swfs 7. Swfs 在 CS5.5 中制作。

在每个入站连接中,我都缺少一行代码:

masterInboundConnection.client = this;

现在一切正常。