Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass JSON to a Flash movie

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

like image 912
Simon_Weaver Avatar asked Jul 08 '09 05:07

Simon_Weaver


2 Answers

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.

like image 144
James Hay Avatar answered Oct 07 '22 20:10

James Hay


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

It should point you in the right direction.

like image 36
Adam Harte Avatar answered Oct 07 '22 22:10

Adam Harte