LocalConnection:简单示例适用于 Flash 10,但不适用于 Flash9
以下代码直接来自任何 Adobe 示例,在 Flash 10 上运行良好,但在 Flash 9 中运行时,发送连接 onStatus
事件收到“错误”。
此示例中的预期行为是在 SWF1 上调用 listeningConnection.ready
方法。
可以在 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'");
}
}
The following code, which is pretty straight out of any Adobe example works fine on Flash 10, but when run in Flash 9, the sending connections onStatus
event receives 'error'.
The expected behavior in this example is that the listeningConnection.ready
method is invoked on SWF1.
A demo of this can be seen on http://easyxdm.net/beta/tests/flash.html (single SWF with conditional logic).
UPDATE
The culprit was Flash's caching mechanism as we were using a single flash with conditional branching and not two individual swf-files.
Anyone know if there was a restriction lifted, or a bug fixed related to this in 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'");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生这个奇怪错误的原因是两个对象标签引用了相同的 SWF 文件。代码会根据提供的变量进行不同的分支,但由于两者使用相同的路径,Flash9 的缓存机制启动并导致错误。
因此,简单的解决方案是在 src 后面使用
?host=true/false
来绕过缓存。The reason why this strange error occurred was that it was the same SWF-file references by the two object-tags. The code would branch differently based on provided variables, but due to the due to the same path being used for both, Flash9's caching mechanism kicked in and caused this to err.
So, the simple solution was to use
?host=true/false
behind the src in order to circumvent the caching.