views:

1439

answers:

2

What is the best way to pass JSON to and from a Flash movie?

Currently to communicate between javascript and Flash :

  • I'm using 'flashvars' to pass data to the flash movie when it initially loads
  • I'm using 'ExternalInterface' at runtime to transfer single values, such as booleans at runtime

I want to move to the next level and do this with JSON now.

Initially I just want the ability to send JSON to the flash movie on instantiation, but later i will need to send data back and forth.

I just want to do it right first time and avoid any compatibility or 'gotcha' issues if there are any. i dont even know if i can pass a whole object to Flash, or if i need to serialize it as a raw JSON string

+1  A: 

This post should be helpful to you: ThanksMister - JSON (Lite)

It should point you in the right direction.

TandemAdam
interesting post ... as a consequence, i'd like to disadvise you from using the library as such, since it is not maintained etc. ... for production level, use the corelib, as pointed out by james ... greetz
back2dos
+4  A: 

As TandemAdam pointed out in his link you will need the AS3Corelib, which gives you access to the JSON class with the static methods JSON.deserialize() and JSON.serrialise().

If you're just communicating with the JavaScript on the page then you will have to continue to pass the JSON strings through ExternalInterface calls.

If you need to communicate with a server you can actually send the JSON strings directly to and from the server using the URLRequest object and URLLoader object.

James Hay