未接收同一 SWF 中多个 SharedObject 的 onSync 删除事件
我有一个使用远程共享对象的应用程序,我看到一些奇怪的行为。我正在使用 Flash Builder 在 AS3 中编写一个 ActionScript 应用程序并连接到 Wowza Media Server 2。
我的应用程序运行良好,但我现在尝试使用 FlexUnit 为其编写单元测试。我的单元测试涉及创建到同一远程 SharedObject 的多个连接,并确保我正确获取更新。一切似乎都运行良好,除了我没有收到任何 info.code 为“delete”的 SyncEvent.SYNC 事件。当我在单独的选项卡甚至嵌入在同一页面中的单独的 swf 中独立运行应用程序时,它工作得很好。由于某种原因,它在单元测试中不起作用。我还发现,如果我使用同一个 SWF 中的 Loader 加载 swf,那么我会得到相同的行为。在我看来,同一个 SharedObject 的倍数在同一个 SWF 中的行为方式似乎有些奇怪。我必须解决单元测试中的其他奇怪行为,例如 onSync 事件中的 oldValues 也没有正确设置。
有人知道我该如何解决这个问题吗?这是一个已知问题吗?我疯了吗? :)
将不胜感激任何帮助!
I have an application that uses Remote SharedObjects and I am seeing some strange behaviour. I am writing an ActionScript application in AS3 using Flash Builder and connecting to Wowza Media Server 2.
My application is working just fine but I am now trying to write unit tests for it using FlexUnit. My unit tests involve creating multiple connections to the same remote SharedObject and making sure that I am getting updates correctly. Everything seems to be working well except that I am not getting any of the SyncEvent.SYNC events with an info.code of "delete". When I run my applications independently in separate tabs or even separate swfs embedded in the same page it works fine. For some reason though it does not work when inside a unit test. I have also found that if I load the swfs using a Loader inside the same SWF then I get the same behaviour. It seems to me to be something strange about the way multiples of the same SharedObject behave within the same SWF. I have had to work around other strange behaviour in the unit tests such as oldValues not being set properly in the onSync events too.
Anyone have any ideas how I can work around this? Is this a known issue? Am I crazy? :)
Would appreciate any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
之前,当我使用 Cairngorm 等编码框架开发一些 Flex 应用程序并使用多个远程对象连接到 AMFPHP 时,我也遇到过这个问题。
当时我想解决这个问题的方法是确保这些远程对象不会同时被触发。这是试图建立一些所谓的“顺序链”来依次发射这些远程对象。
为了实现这一点,如果您从头开始可能会很困难,您可以考虑使用那些现代的 ActionScript 框架 2.0 来帮助您(例如 SWIZ 或 Robotlegs)。这在一开始可能太复杂而无法处理。我建议您只需放置要由框架处理的远程对象部分,同时保持其他内容不变。
I also faced this problem before when I was working on some Flex application using some coding frameworks like Cairngorm, and connecting to AMFPHP with multi remote objects.
At that time what I come up with to resolve the issue is to make sure that those remote objects won't be fired at the same time. That is trying to make some so called "sequential chain" to fire those remote objects one after another.
In order to achieve this it may be difficult if you do it from scratch, you may consider making use of those modern ActionScript framework 2.0 to help you (e.g. SWIZ or Robotlegs). This may be too complex to handle in the very beginning. I suggest you can just place the remote object parts to be handled by the framework while keeping other things intact.
要获取您的sharedObject实例,您可以使用静态方法
SharedObject.getRemote()
。我相信此方法将始终为给定名称返回相同的实例(并且如果持久性参数具有相同的值)。当您从应用程序中删除 SharedObject (
mySO = null
) 并在垃圾收集器完成其工作之前重新实例化它时,可能会遇到同样类型的问题。这种行为对我来说是有道理的,但有时它可能是一个我必须承认的问题。无论如何,在调试会话中测试应该很容易(查看您的对象实例编号)。
现在谈论单元测试,你在测试什么?共享对象的行为?如果是这样,我相信这里存在一些误解。如果您确实想测试这种行为(并且我对背后的原因感兴趣),那么我想您将需要一些运行两个单独应用程序的更复杂的测试。
希望有帮助!
To get your sharedObject instance, you are using the static method
SharedObject.getRemote()
. I believe this method will always return the same instance for a given name (and if the persistence parameter has the same value).You can have the same kind of issue when you remove a SharedObject from your app (
mySO = null
) and you reinstantiate it before the garbage collector did its job).This kind of behavior makes sense to me, but it can sometimes be a problem I must admit. Anyway it should be easy to test in a debug session (Have a look at your objects instance number).
Now talking about unit tests, what are you testing? The SharedObjects behavior? If so, I believe there is some misconception here. It you really want to test this kind of behavior (and I would be interested in the reason behind), then I guess you will need some more complex tests that run two separate applications.
Hope it helps!
我们的项目中的删除也有类似的行为。
当我们调用so.close()时。然后删除共享对象中的一些键。然后再次连接 SO - 它仍然看到已删除的密钥还活着。
解决方法:不要关闭 SO 或使用某些常量值(例如 -2)更新已删除的键以将其标记为已删除。
使用Wowza 3。
We had similar behavior with deletes in our project.
When we call so.close(). Then delete some key in shared object. Then connect SO again - it still see deleted key alive.
Workarounds: do not close SO or update deleted keys with some constants values (-2 for example) to mark them deleted.
Wowza 3 was used.