在 AS3 swf 中写入本地 SharedObject 并在加载的 AS2 swf 中读取它
我正在尝试在加载的 as3 swf 和 as2 swf 之间共享数据。问题是,我似乎无法让我的 as2 swf 读取 as3 swf 写入的本地共享对象。当我尝试获取对共享对象的引用时,它只是返回未定义,
// AS3
_SharedObj.objectEncoding = ObjectEncoding.AMF0;
_SharedObj.data.blah = 'str';
_SharedObj.flush(500);
// ... some code to handle the flush status. I verified that the values were flushed.
// AS2
var so = SharedObject.getLocal('somestr', '/');
trace(so); // undefined!
我在这里不知所措。我可以从 AS3 读取 AS2 共享对象,但不能以其他方式执行此操作。我已经验证两者都引用相同的路径“/”(特别是本地主机,我什至检查了文件系统中的物理文件,-它位于我的Mac上#SharedObjects目录的#localhost目录中)objectEncoding设置为使用AS2 AMF 格式。
文档特别指出设置此编码以允许 as2 访问相同的共享对象,所以我认为这意味着这是可能的。
有人有什么想法吗?
I am trying to share data between an as3 swf and a as2 swf that it loaded. The problem is, I can't seem to get my as2 swf to read the localshared object written by the as3 swf. It simply returns undefined when I try to get a reference to the shared object
// AS3
_SharedObj.objectEncoding = ObjectEncoding.AMF0;
_SharedObj.data.blah = 'str';
_SharedObj.flush(500);
// ... some code to handle the flush status. I verified that the values were flushed.
// AS2
var so = SharedObject.getLocal('somestr', '/');
trace(so); // undefined!
I am at a loss here. I can read the AS2 sharedobject from AS3, but I can't do it the other way. I have verified that both are referencing the same path '/' (specifically localhost, I even checked the physical file in the filesystem, - its in the #localhost directory of the #SharedObjects directory on my mac) The objectEncoding is set to use the AS2 AMF format.
The docs specifically say to set this encoding to allow as2 to access the same shared object, so I assume it means this is possible.
Anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 FlashDevelop 时,无法弄清楚什么对您不起作用,以下代码非常适合我:
Can't figure what is not working for you, when using FlashDevelop, the following code works perfect for me:
您的问题是为 Flash Player 生成的 swf id 并由它用于 SharedObject 使用。您在代码中看不到这一点,但当您搜索 SharedObject 文件时,您会看到它。这就是安全功能。我不知道有什么解决办法。
Your problem is swf id generated for Flash Player and use by it for SharedObject use. You don't see this in code but when you search for SharedObject file then you see it. That is safety feature. I don't know any work around for that.
我遇到了类似的问题 - 我们最终采用了使用 AS2 SWF 读取/写入 LSO 的令人发指的路线,并让它通过 JavaScript/ExternalConnection 与 AS3 SWF 通信。虽然很糟糕,但它工作可靠。
I ran into a similar problem -- we eventually went the heinous route of reading/writing the LSO with an AS2 SWF, and having it talk to the AS3 SWF via JavaScript/ExternalConnection. It was gross, but it worked reliably.
我遇到了同样的问题,我认为 Dudi 上面的答案是正确的方法 - 在调用 SharedObject.getLocal() 后,我在代码中添加了以下行,并且我的 AS2 swf 能够加载我的 AS3 编写的共享对象。
谢谢杜迪!
I had the same problem and I think Dudi's answer above is the way to go - I added the following line to my code after calling SharedObject.getLocal() and my AS2 swf was able to load my AS3 written Shared Object.
Thanks Dudi!