以下代码非常直接地来自任何 Adobe 示例,在 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'");
}
}