Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to enable communication between Javascript and Flash via ExternalInterface across domains. The Javascript works great when it is located on the same domain as the SWF. But in one case, the HTML resides on domain A, the javascript and the flash both reside on domain B. I have done all of the following:

  • The embed tag has allowScriptAccess="always" (and the object has that as a param)
  • My SWF file's actionscipt has Security.allowDomain("*")
  • My SWF also calls Security.allowInsecureDomain("*")
  • Both domain A and domain B have a /crossdomain.xml file which has allow-access-from domain="*"

The SWF is able to call javascript on the page, but when I use Javascript to call functions exposed by ExternalInterface, I get

Error calling method on NPObject! [plugin exception: Error in Actionscript. Use a try/catch block to find error.]

This is ActionScript 2 so ExternalInterface.marshallExceptions is not available.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
150 views
Welcome To Ask or Share your Answers For Others

1 Answer

You should only need two things for this to work:

1) allowscriptaccess=always will allow your swf to send stuff out to the page

2) System.security.allowDomain("yourhtmldomain.com");

Note that it's System.security.allowDomain() in AS2 - it's not the same as AS3 or what you have written above.

number 2 above allows the html page on domainA to call things in the swf on domainB.

The domain your js is hosted on won't matter here, since the browser embeds it on domainA, the script is executed in domainA.

crossdomain.xml is mainly only for loading remote files, which you aren't doing, so you can remove that if you like. (and you probably don't want to have a crossdomain.xml file with allow="*" sitting on your main domain, that's very bad practice)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...