使用 SWFObject 复杂的 FlashVar 对象?

发布于 2024-10-01 19:51:50 字数 520 浏览 3 评论 0原文

是否可以使用 SWFObject 将本机 JavaScript 对象(例如数组和类似哈希映射的对象)传递到 Flash Player?

我基本上需要将 Flash 变量中的 JavaScript 对象数组传递给 Flash,所以这是我的代码:

swfobject.embedSWF("application.swf", "divvy" "100%", "100%", null,
    { 'info': [
        { 'id': 1, 'name': "Hello, John" },
        { 'id': 2, 'name': "Hello, Dave" }
    }]);

当我在 Flex 中获取对象时,我只需得到一个如下所示的字符串:“[Object object], [Object object]”,这让我相信我的数组在进入 Flash 之前已被序列化为字符串。有任何已知的解决方法吗?

是的,我确实需要以这种方式传递 Flash 变量,因为它们会关闭应用程序启动之前必须执行的一些加载。

Is it possible to pass native JavaScript objects such as arrays and hash-map-like objects to Flash Player with SWFObject?

I basically need to pass an array of objects to Flash from JavaScript in the Flash variables, so this is my code:

swfobject.embedSWF("application.swf", "divvy" "100%", "100%", null,
    { 'info': [
        { 'id': 1, 'name': "Hello, John" },
        { 'id': 2, 'name': "Hello, Dave" }
    }]);

When I get the object in Flex, I simply get a String that looks like this: "[Object object], [Object object]" which leads me to believe that my array is being serialized into a String before entering Flash. Is there any known workaround?

And yes, I do need to pass Flash variables in this manner, since they'll key off some loading which is necessary to do before the application starts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

一杯敬自由 2024-10-08 19:51:50

使用 as3corelib 中的 JSON lib 并将整个对象编码为 json 对象,它将成为 flash 对象一旦其反序列化。您可能需要对json字符串进行urlencode以将其作为字符串传递,一旦它进入as3,它将被de-urlencoded,并且您可以使用as3corelib的json函数对其进行反序列化,并且您将在flash中拥有一个代表您的数据的对象。

Use the JSON lib from as3corelib and pass the entire object encoded as a json object and it will become a flash object once its deserialized. You might need to urlencode the json string to pass it as a string, once it gets into as3 it will be de-urlencoded, and you can unserialize it using the as3corelib's json function, and you will have a object in flash that represents your data.

寂寞清仓 2024-10-08 19:51:50

复杂对象必须通过 flashvars 作为字符串发送,然后您可以使用 as3corelib 的 JSON 解析器来读取它。

或者,您可以使用 ExternalInterface 调用 JavaScript 函数按原样返回对象。

正如评论中所建议的,您可以让 Flash 从服务器本身请求数据,有很多方法可以做到这一点。

The complex object must be sent as a string via flashvars, you could then use as3corelib's JSON parser to read it.

Alternatively you could use ExternalInterface to call a javascript function to return the object as is.

As was also suggested in the comments, you could have Flash request the data from the server itself, there's a lot of ways this can be done.

黄昏下泛黄的笔记 2024-10-08 19:51:50

答案:正如 @Robusto 上面提到的不可能通过 Flashvars 将原生 JavaScript 对象传递给 Flash Player。我忘记了 Flash 变量只是 SWF 的 GET 参数,仅此而已。因此,application.swf?r=123swfobject.embedSWF('application.swf', '100%', '100%', null, {'r' : 123}, null);

我可能只加载一些 XML 之类的东西。

Answer: as @Robusto mentioned above it is not possible to pass native JavaScript objects to Flash Player via Flashvars. I forgot that Flash variables are simply GET parameters to the SWF, nothing more. Thus, application.swf?r=123 is the same thing as swfobject.embedSWF('application.swf', '100%', '100%', null, {'r': 123}, null);

I'll probably just load some XML or something.

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