在 AS3 swf 中写入本地 SharedObject 并在加载的 AS2 swf 中读取它

发布于 2024-08-07 20:47:18 字数 656 浏览 2 评论 0原文

我正在尝试在加载的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不羁少年 2024-08-14 20:47:18

使用 FlashDevelop 时,无法弄清楚什么对您不起作用,以下代码非常适合我:

//AS3
var so : SharedObject = SharedObject.getLocal('somestr', '/');
so.objectEncoding = ObjectEncoding.AMF0;
so.data.blah = 'str';
so.flush();

//AS2
var so = SharedObject.getLocal('somestr', '/'); 
trace(so.data.blah);  // str

Can't figure what is not working for you, when using FlashDevelop, the following code works perfect for me:

//AS3
var so : SharedObject = SharedObject.getLocal('somestr', '/');
so.objectEncoding = ObjectEncoding.AMF0;
so.data.blah = 'str';
so.flush();

//AS2
var so = SharedObject.getLocal('somestr', '/'); 
trace(so.data.blah);  // str
反目相谮 2024-08-14 20:47:18

您的问题是为 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.

风追烟花雨 2024-08-14 20:47:18

我遇到了类似的问题 - 我们最终采用了使用 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.

2024-08-14 20:47:18

我遇到了同样的问题,我认为 Dudi 上面的答案是正确的方法 - 在调用 SharedObject.getLocal() 后,我在代码中添加了以下行,并且我的 AS2 swf 能够加载我的 AS3 编写的共享对象。

so.objectEncoding = ObjectEncoding.AMF0

谢谢杜迪!

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.

so.objectEncoding = ObjectEncoding.AMF0

Thanks Dudi!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文