0

以下代码非常直接地来自任何 Adob​​e 示例,在 Flash 10 上运行良好,但在 Flash 9 中运行时,发送连接onStatus事件会收到“错误”。

此示例中的预期行为listeningConnection.ready是在 SWF1 上调用该方法。

可以在http://easyxdm.net/beta/tests/flash.html上看到一个演示(带有条件逻辑的单个 SWF)。

更新 罪魁祸首是 Flash 的缓存机制,因为我们使用的是带有条件分支的单个 Flash,而不是两个单独的 swf 文件。

任何人都知道 Flash 10 中是否取消了限制或修复了与此相关的错误?

SWF1

public static function main(swfRoot:MovieClip):Void 
{
    var channelName = "_channel";
    var listeningConnection:LocalConnection  = new LocalConnection();

    listeningConnection.ready = function() {
        ExternalInterface.call("console.log", "ready");
    };

    listeningConnection.allowDomain = function(domain) {
        return true;
    };

    if (listeningConnection.connect(channelName)) {
        ExternalInterface.call("console.log","listening on " + receivingChannelName);   
    } else {
        ExternalInterface.call("console.log","could not listen on " + receivingChannelName);    
    }
}

SWF2

public static function main(swfRoot:MovieClip):Void 
{
    var channelName = "_channel";
    var sendingConnection:LocalConnection = new LocalConnection();

    sendingConnection.onStatus = function(infoObject:Object) {
        switch (infoObject.level) {
            case 'status' :
                ExternalInterface.call("console.log", "LocalConnection connected successfully.");
                break;
            case 'error' :
                ExternalInterface.call("console.log", "LocalConnection encountered an error.");
                break;
        }
    };

    if (sendingConnection.send(channelName, "ready")) {
        ExternalInterface.call("console.log", "called 'ready'");
    }else{
        ExternalInterface.call("console.log", "error calling 'ready'");
    }
}
4

1 回答 1

1

发生这个奇怪错误的原因是两个对象标签引用了相同的 SWF 文件。代码会根据提供的变量进行不同的分支,但由于两者使用相同的路径,Flash9 的缓存机制启动并导致此错误。

因此,简单的解决方案是?host=true/false在 src 后面使用以规避缓存。

于 2011-04-25T11:40:52.630 回答