使用 SWFObject 复杂的 FlashVar 对象?
是否可以使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 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.
复杂对象必须通过 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.
答案:正如 @Robusto 上面提到的不可能通过 Flashvars 将原生 JavaScript 对象传递给 Flash Player。我忘记了 Flash 变量只是 SWF 的 GET 参数,仅此而已。因此,
application.swf?r=123
与swfobject.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 asswfobject.embedSWF('application.swf', '100%', '100%', null, {'r': 123}, null);
I'll probably just load some XML or something.