0

LocalConnection を使用して、別々のブラウザ ウィンドウ (最初に開いたページですべて開いた) にロードされた 3 つの swfs 間の通信をセットアップしようとしています。私はインター SWF 通信が初めてで、ここにあるチュートリアルに従っています。

テストのために xampp サーバーからこれらを実行しています。

基本的に、私は3つのswfsを持っています。私は 1 つの「マスター」swf と 2 つの「スレーブ」swf を持っています。マスター SWF を起動すると、他の両方の SWF が新しいウィンドウで開きます。マスターでボタンをクリックすると、スレーブの 1 つでテキストを更新しようとしています。もっと複雑なことは後で起こります。最初に 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++;
    }   

}

スレーブ1:

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>

通信をトリガーするはずのボタンをクリックしても、何も起こらないようです。

Windows 7 のローカルホスト xampp サーバーの IE11 でこれらの swfs を含む html ページを実行しています。CS5.5 で作成された SWFS。

4

1 に答える 1

0

各インバウンド接続で、1 行のコードが欠落していました。

masterInboundConnection.client = this;

現在、すべてが期待どおりに機能しています。

于 2016-09-15T19:14:47.610 に答える