Mike Chambers has a post over on his blog about a new “Flash / Javascript Integration Kit.”
What does it do? It lets you send Data from Javascript into your Flash movies (and back out, of course). At first I was skeptical, since you can’t talk to Flash using Javascript in quite a few browsers (Safari being one of the bigger ones), so I decided to dig into it and see how it works.
I’ll skip over the Data handling, since it’s fairly basic to package Objects and Arrays and whatnot into strings and back out into real data again. What I was really interested in was how they got Javascript communicating with Flash movies without reloading the page or loading data into the Flash movie at specified intervals.
Here’s how it works: First you set up your main Flash movie how you normally would, and add in their custom data handler class (JavaScriptSerializer) and their proxy class (JavaScriptProxy). Then when you want to send data into your Flash movie, you call a JS function which creates a 1px by 1px Flash movie on the page, and passes in the data as FlashVar string. Then, this little Flash movie sets up a LocalConnection object with your main movie and passes the data into it where it is unserialized and calls to whatever functions you wanted to call are made.
Seems like quite a bit of work, but I’ve seen a few projects come and go that might benefit from being able to talk back and forth with Javascript on the same page.