在Flash中使用双向localConnection时可能导致连接错误的原因是什么?

时间:2022-11-25 03:44:56

I'm trying to setup a bidirectional localConnection (LC) between two flash objects on the same web page. One object is AS2 and the other AS3.

我正在尝试在同一网页上的两个Flash对象之间设置双向localConnection(LC)。一个对象是AS2,另一个是AS3。

  1. I'm using one LC object to send and receive data on each swf. (This shouldn't matter, right? I tried using two objects, one for sending and one for receiving, but got the same problem).
  2. 我正在使用一个LC对象在每个swf上发送和接收数据。 (这应该没关系,对吧?我尝试使用两个对象,一个用于发送,一个用于接收,但是遇到了同样的问题)。

They .connect() properly so that they both listen. But I'm getting errors when I'm trying to send data from the AS2 SWF to the AS3 LC. This happens 95% of the time, but sometimes it DOES work, so I know it's not a problem with the LC names (I checked, obviously)

他们.connect()正确,以便他们都听。但是当我尝试将数据从AS2 SWF发送到AS3 LC时,我遇到了错误。 95%的情况下会发生这种情况,但有时它会起作用,所以我知道这不是LC名称的问题(我明确检查过)

Sometimes one or two messages go through and consequtive messages fail.

有时一两条消息会通过,而连续的消息也会失败。

Any idea on what might cause it?

有什么可能导致它的想法吗?

I'm aiming to create a many-to-one connection map so that many AS2 swfs could connect to the one AS3 swf. Will that be a problem?

我的目标是创建一个多对一的连接映射,以便许多AS2 swfs可以连接到一个AS3 swf。这会有问题吗?

3 个解决方案

#1


2  

One possible cause is that I've noticed that multiple listeners to the same LC name seem not to work. To see what I mean, open this page on two different tabs, and you should see that both of the "sending" SWFs work, but the message is only received on the first tab you opened. I guess you're only using two SWFs, but if they're both trying to listen to the same LC name, perhaps you're seeing something similar?

一个可能的原因是我注意到同一个LC名称的多个监听器似乎无法工作。要查看我的意思,请在两个不同的选项卡上打开此页面,您应该看到两个“发送”SWF都有效,但只会在您打开的第一个选项卡上收到该消息。我猜你只使用两个SWF,但如果他们都试图听同一个LC名称,也许你会看到类似的东西?

Also, I believe LC is, in some way, disabled for SWFs that are inside invisible page elements, or possibly even just offscreen. Are you doing anything like that?

另外,我认为LC在某种程度上对于不可见页面元素内部的SWF是禁用的,甚至可能只是在屏幕外。你在做那样的事吗?

#2


0  

You don't by chance have two different browsers open to the same page do you? LocalConnection will connect across browsers which may cause that issue.

你不是偶然有两个不同的浏览器打开到同一页面吗? LocalConnection将跨浏览器连接,这可能会导致该问题。

Usually what I do to ensure the LC names are unique is to generate a random LC name on the server, then pass that LC name to both swfs using FlashVars.

通常我要确保LC名称是唯一的,就是在服务器上生成一个随机LC名称,然后使用FlashVars将该LC名称传递给两个swfs。

It may also have something to do with the order in which the swf's load. It may be that the swf listening for the connection is loading after the swf creating the connection tries to connect. Then, the other 5% of the time, the swf's load in the correct order. Maybe if an error occurs, just try to connect again.

它也可能与swf的加载顺序有关。可能是在创建连接的swf尝试连接之后,正在加载侦听连接的swf。然后,另外5%的时间,swf的负载按正确顺序排列。也许如果发生错误,只需尝试再次连接即可。

#3


0  

I finally figured out what caused the problem.

我终于找到了导致问题的原因。

It seems that although in AS3 you can use the same LC object to send AND receive events, doing so in AS2 will give you errors after a while (probably when trying to send after receiving).

似乎虽然在AS3中您可以使用相同的LC对象来发送和接收事件,但在AS2中这样做会在一段时间后给您错误(可能在接收后尝试发送)。

#1


2  

One possible cause is that I've noticed that multiple listeners to the same LC name seem not to work. To see what I mean, open this page on two different tabs, and you should see that both of the "sending" SWFs work, but the message is only received on the first tab you opened. I guess you're only using two SWFs, but if they're both trying to listen to the same LC name, perhaps you're seeing something similar?

一个可能的原因是我注意到同一个LC名称的多个监听器似乎无法工作。要查看我的意思,请在两个不同的选项卡上打开此页面,您应该看到两个“发送”SWF都有效,但只会在您打开的第一个选项卡上收到该消息。我猜你只使用两个SWF,但如果他们都试图听同一个LC名称,也许你会看到类似的东西?

Also, I believe LC is, in some way, disabled for SWFs that are inside invisible page elements, or possibly even just offscreen. Are you doing anything like that?

另外,我认为LC在某种程度上对于不可见页面元素内部的SWF是禁用的,甚至可能只是在屏幕外。你在做那样的事吗?

#2


0  

You don't by chance have two different browsers open to the same page do you? LocalConnection will connect across browsers which may cause that issue.

你不是偶然有两个不同的浏览器打开到同一页面吗? LocalConnection将跨浏览器连接,这可能会导致该问题。

Usually what I do to ensure the LC names are unique is to generate a random LC name on the server, then pass that LC name to both swfs using FlashVars.

通常我要确保LC名称是唯一的,就是在服务器上生成一个随机LC名称,然后使用FlashVars将该LC名称传递给两个swfs。

It may also have something to do with the order in which the swf's load. It may be that the swf listening for the connection is loading after the swf creating the connection tries to connect. Then, the other 5% of the time, the swf's load in the correct order. Maybe if an error occurs, just try to connect again.

它也可能与swf的加载顺序有关。可能是在创建连接的swf尝试连接之后,正在加载侦听连接的swf。然后,另外5%的时间,swf的负载按正确顺序排列。也许如果发生错误,只需尝试再次连接即可。

#3


0  

I finally figured out what caused the problem.

我终于找到了导致问题的原因。

It seems that although in AS3 you can use the same LC object to send AND receive events, doing so in AS2 will give you errors after a while (probably when trying to send after receiving).

似乎虽然在AS3中您可以使用相同的LC对象来发送和接收事件,但在AS2中这样做会在一段时间后给您错误(可能在接收后尝试发送)。