views:

179

answers:

1

Hello, everyone!

I have some problems with Adobe Air. My application has rather complicated architecture: the main html window loads iframe with references to javascripts (e.g. DWRengine.js, jquery.js, main.js and so on). It's done to avoid Air's javascript restrictions on 'eval' function, which is widely used in my scripts and in DWR too.

In main.js file I'm trying to add event listeners to main window's buttons and links.

Like this:

$(document).ready(function(){
    $('body', top.document).click(function(){alert('a');});   
});

But there's no effect! top.document is undefined.

I can't bind actions to events while loading main page, because objects containing them are loaded only after main page onload event.

Help me, please!

Thanks in advance, Mike.

A: 

You're working in two different sandboxes so you'll need to set up a sandbox bridge.

In your case you'll have to expose in interface to methods in the application sandbox using the parentSandboxBridge

here are the docs in case you don't have them

So in the top window

// quoting from the docs
var interface = {};
interface.save = function(text){
    var saveFile = air.File("app-storage:/save.txt");
    //write text to file
}
document.getElementById("yourIframe").contentWindow.parentSandboxBridge = interface;

Of course this won't make your libraries available in the parent but you can process in the child and use the parent to do the air stuff

meouw
Thank you, it helped, but didn't solve whole problem. Now I can call functions from my libraries, but most of their action is using jquery for showing and hiding elements. As far as jquery is loaded and called from iframe, it uses iframe document, not the main window document as intended.
Mikhail
I don't think you are going to be able to reference elements in one sandbox from the other. Why not let the iframe contain the entire UI and only use the application to do air stuff like cross domain requests and filesystem access
meouw
Also, what are you eval() ing? if it's just JSON from a ajax response, air allows that.
meouw
Thank you again. I moved UI into non-application sandbox and now it works well!
Mikhail