2008-08-28

AIR and the pitfalls of the Security Sandbox (and eternal damnation of Singletons)

For a few days now I've been working on an AIR application to generate XML for a product called Sound Manager. Sound Manager, which we built for a client of ours - DinahMoe, is a pretty nifty system which allows them to hand over a couple of as-files to their clients through which the end client's developers can dispatch events describing what's going on in the Flash app. DinahMoe can then orchestrate sounds for the app by linking the events to actions playing, stopping, pausing, transforming, jumping and so forth, in sounds.

In order to lower the complexity for the end client, we put all the code that actually does anything into the sound libraries that are compiled by the guys at DinahMoe (or is it just guy, Johan?). The objects in the sound libraries then listen for the Sound Managers events and do what has to be done... and what has to be done is off course described in XML.

So the AIR admin lets DinahMoe build the XML through a rich interface where actions can be categorized in folders, copied, edited and so on. Then it was time for the testing. In short, I wanted the AIR app to instanciate the SoundManager, tell it to load the XML and the sound libs and then fire the events I wanted to test. Here's where everything goes pear shaped. The AIR app lives in the Application Sandbox, the loaded swf:s liv in the Loca file Sandbox. So they each instanciate their own singletons and all communication is lost.

So I built a swf which instanciates the SoundManager, and let the AIR app load the SWF... but as it was placed inside the apps application directory, it was too run in the Application Sandbox. So I copied it to the same directory as the Sound libraries that were to be loaded... and now they all ended up in the same Sandbox... but still they could not communicate. And here's where I lost hope. So now I return handles through the SoundLibraries and call each and everyone of them with each event. Not pretty but It's the best I could com up with.

So what is the deal? Are SWF:s in the Local File Sandbox prohibited from talking to each other? Is there a solution? Anyone?

No comments: