views:

36

answers:

4

I'm developing an iFrame Facebook application. The iFrame has a swf. We need to get access to that swf through javascript.

This iFrame has a swf that needs to be put inside a Javascript variable so that we can call ExternalInterface functions from.

Right now, our "flash" variable is undefined because we can't seem to access elements of that iFrame, as that evokes a sandbox security warning, as evoking window or document in this way means we're accessing this content from the parent's site, which is Facebook.

Right now, we're doing something like:

if(navigator.appName.indexOf("Microsoft") != -1)
{
     flash =  window["swfr"];
 }
 else
 {
    flash = document["swfr"];
  }

I'm sure there's a way to make this work, but unfortunately, I'm just not seeing it. I appreciate any help.

A: 

Possibly Related ?

ken
Running the app standalone works - everything works like it should. It's only in the context of when the source is in an iFrame does everything break, although I will give what Christian suggested a try.
L.S. Valis
A: 

The child iframe page has a reference to the parent, not the other way around. So you should be able to give a back reference then use that to manipulate your flash object. This blog shows how to call a parent function (you pass the flash obj as a reference): http://www.velocityreviews.com/forums/t164727-a-challenge-call-parent-javascript-function-from-inside-an-iframe.html

parent page:

function ManipulateFlashObj(obj)
{
alert(obj);
}

child (iframe page):

parent.ManipulateFlashObj(document.getElementById("swf"));
Russell
So I can't manipulate elements of an iFrame from the iFrame itself, I have to use references to the parent to do that?
L.S. Valis
A: 

If the parent page and the iframe page are on different DNS domains, the browser will not allow the parent to see into the child context nor the child to see the parent context. To move data between the parent and child, you'll need to use cross-domain scripting techniques (XSS) such as passing data on the iframe URL.

dthorpe
A: 

It should work if the script is within the IFrame, since the IFrame will have the same domain as the SWF file. If, however, the iframe is served from some facebook URL, you'll have to create/update the cross-domain.xml file on the host which serves the SWF.

Also, try swfObject, as it has a much wider browser compatibility, and is even used by Flash Builder 4 in the auto generated html template.

http://code.google.com/p/swfobject/

Derrick