Request a topic or
Contact an Arke consultant
404-812-3123
Flash talking to Javascript

Arke Systems Blog

Useful technical and business information straight from Arke.

About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Flash talking to Javascript

For the past few versions of Shockwave Flash, loading a flash object from a browser is no longer a one-way street.  Flash objects can interact with the browser, including calling Javascript, and the browser can interact with Flash, including Javascript calling Flash's ActionScript.

There are some security restrictions in place - ActionScript has to be registered via ExternalInterface.addCallback, and by default you can't call scripts across servers.  But we were running into a problem I haven't seen clearly explained anywhere - calls from Flash to Javascript weren't working right only when displayed in Mozilla. A simple test with window.parent.doTest() worked in IE, not in Netscape.

It turns out that Mozilla has wrapped the Javascript object model in XPCNativeWrapper as part of a security fix a while back.  Unfortunately, part of the functionality of this wrapper includes hiding any Javascript functions outside of the 'self' container.

So, for Javascript calls to work right in Netscape, they need to only call functions in the self container (i.e. the javascript needs to be in the head for the current iframe.)  If you try to embed the .swf directly in an iframe, it won't be able to call any Javascript. 

Changing out test to self.doTest(), and moving the definition of the doTest function inside of the current iframe's HTML, fixed the problem.  But, we have to change our app a bit - previously the iframe directly included the .swf, and there is no way to make the Javascript available that way.

Maybe this is documented clearly somewhere, and if so, I'd love to know the link so that I can have better docs to review next time I'm stuck.  So far About exchanging data with Flex applications has been useful, but everything else I could find about flash javascript problems just pointed to the allowScriptAccess parameter Adobe added to combat cross site scripting.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by David Eison on Friday, February 08, 2008 1:46 PM
Permalink | Comments (1) | Post RSSRSS comment feed

Related posts

Comments

Ryan us

Thursday, June 12, 2008 8:32 PM

Ryan

I ran into this problem and this is one of only... well, one article on the entire internet that I could find that deal specifically with this issue as it relates to Flash and iframes (I guess it's a kind of exotic mixture of technologies). Kudos for however you figured this out.

Just wanted to add that based on this Mozilla doc: developer.mozilla.org/en/docs/XPCNativeWrapper , I've had luck busting out of this security wrapper by using the wrappedJSObject property of XPCNativeWrapper. The caveats are 1) that the doc says you should never do this in production code and 2) that Firefox 3 will add another layer of wrapper under this property that is likely to break the workaround or at least require some more workaround code.

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

Friday, September 05, 2008 5:06 PM