(as3) 在同一页面上3个或更多相同的闪存对象之间同步数据
我以前问过类似的问题,但从未找到我需要的解决方案。因此,我开始一个新的堆栈,以免混淆我的问题,并使问题更加清晰。
我需要做什么
我在一个 html 页面上有多个 flash 对象,它们都是相同的,并且所有这些对象都需要与正确的时间同步。在当前状态下,每个人都会查询时间服务器并获取时间,这非常有效。但我想要实现的是第一个加载的对象是唯一与时间服务器同步的对象,然后其他闪存对象等待它完成,并从该对象加载同步时间。
问题
共享对象: 从纸面上看,这似乎是完美的解决方案,我加载第一个来保存 SO“timestarted”,如果此后有任何加载闪存看到此 SO,它会等待创建“synctime”SO,然后加载该 SO ...伟大的!但是没有... SharedObjects 似乎只在加载闪存时加载 SO,闪存加载后的任何更改或新 SO 对于创建它的闪存之外的任何其他闪存来说都是完全未知的! (直到重新加载闪存)...doh
LocalConnection: 有点复杂,但听起来是一个很好的解决方案,除了只有一个闪光灯可以随时打开连接之外,啊!
我需要什么
简单来说,我需要一种方法让一个 flash 对象将自己声明为同步器,而其他对象则监听!本来以为很简单的事情,结果却变得如此复杂。我需要任何建议,关于该怎么做的建议。
I have asked something similar before, but never go to the solution I need. So am starting a new stack to not confuse my issues, and to make a little clearer.
What I need to do
I have multiple flash objects on a html page, they are all identical, and all of them need to be sync'd with the correct time. In its current state, each one queries the timeserver, and gets the time, which works great. BUT what I want to achieve is the first one to load to be the only one that sync's with the time server, and then the other flash objects wait for it to finish, and load the sync time from that one.
The Problem
SharedObjects:
On paper, this seamed like the perfect solution, I get the 1st one to load to save a SO "timestarted", if any loading flash after that sees this SO, it waits for a "synctime" SO to be created, and load that...great! But no... SharedObjects only appear to load the SO at the time of loading the flash, any changes, or new SO after the flash loads is completely unknown to any other flash than the one that created it! (until the flash is reloaded)...doh
LocalConnection:
A little more complicated, but sounded like a good solution, apart from only one flash can have the connection open at any one time, gah!
What I need
In simple terms I need a way to have one flash object declare itself as the sync'er, and the others to listen up! Something I thought would be so simple, but turning out to be so complicated. I need any suggestions, advice on what to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您可以使用一点点 javascript,则可以使用 外部接口。让电影调用一个小的 js 脚本来跟踪加载时间的人,然后让其他闪光灯注册回调。一旦第一个 flash 有时间,调用 js 并让它更新其他两个。
If you can use a tiny bit of javascript you can do this using ExternalInterface. Have the movies call out to a small js-script that keeps track of whoever is loading the time, then have the other flashes just register callbacks. Once the first flash has the time, call out to the js and let that update the other two.
我认为您真正要寻找的是 LocalConnection 对象 https://www.adobe .com/livedocs/flash/9.0/ActionScriptLangRefV3/
它允许您的 swf 相互对话。
I think what you are really looking for is the LocalConnection object https://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/
It'll allow your swf's to talk to each other.
也许我误解了这个问题,但这有效:
第一个 swf(同步器):
Maybe I'm misunderstading the question, but this works:
1st swf (syncher):