开发者

Complex FlashVar objects using SWFObject?

开发者 https://www.devze.com 2023-01-24 05:32 出处:网络
Is it possible to pass native JavaScript objects such as arrays and hash-map-like objects to Flash Player with SWFObject?

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 obj开发者_如何学编程ects 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.


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号