admin管理员组文章数量:1405393
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.
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.
Share asked Nov 10, 2010 at 21:21 Naftuli KayNaftuli Kay 92k108 gold badges286 silver badges430 bronze badges 2- 1 You don't have to pass Flash variables in that manner, and in fact you can't, at least not in the way you show here. What you can do is let it connect to the server and get the data before you let the app begin running. Show a progress bar until your data arrives. – Robusto Commented Nov 10, 2010 at 21:27
- Dead on, thanks. I forgot that Flash vars are simply URL variables, not actual JavaScript objects – Naftuli Kay Commented Nov 10, 2010 at 21:45
3 Answers
Reset to default 6Use the JSON lib from as3corelib and pass the entire object encoded as a json object and it will bee 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.
The plex 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 ments, you could have Flash request the data from the server itself, there's a lot of ways this can be done.
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.
本文标签: javascriptComplex FlashVar objects using SWFObjectStack Overflow
版权声明:本文标题:javascript - Complex FlashVar objects using SWFObject? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744884014a2630377.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论