0
以下代码可以很好地适用于Flash 10,但在Flash 9中运行时,发送连接onStatus
事件会收到“错误”。LocalConnection:简单示例适用于Flash 10,但不适用于Flash9
本例中的预期行为是在SWF1上调用listeningConnection.ready
方法。
可以在http://easyxdm.net/beta/tests/flash.html(具有条件逻辑的单个SWF)上看到此演示。
UPDATE 罪魁祸首是闪存的缓存机制,因为我们使用与条件分支单一闪存而不是两个单独的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'");
}
}