Javascript在不同的域上没有调用Flash

时间:2012-11-07 22:15:52

标签: javascript html flash flex

我正在尝试使用Javascript来调用flash函数。当html文件和swf在同一个域上时,我有它工作,但当它在另一个域上时它停止工作。

以下是我在服务器上使用SWF的跨域文件:

<?xml version="1.0"?>
   <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
   <cross-domain-policy>
<site-control permitted-cross-domain-policies="all"/>
   <allow-access-from domain="*" />
   <allow-http-request-headers-from domain="*" headers="*"/>
   </cross-domain-policy>

SWF先前已加载:

AC_FL_RunContent("src", "http://www.eyespeakpro.com/OneSentenceLogin.swf",
    "width", "100%",
    "height", "80%",
    "align", "middle",
    "id", "OneSentenceLogin",
    "quality", "high",
    "bgcolor", "#ffffff",
    "name", "OneSentenceLogin",
    "allowScriptAccess","sameDomain",
    "type", "application/x-shockwave-flash",
    "pluginspage", "http://www.adobe.com/go/getflashplayer"
);

这是javascript代码,当它是另一台服务器上的html页面的一部分时失败。 SWF称为OneSentenceLogin,函数是callChangeSentIn。

 function callExternalInterface(sentIn) {
    /* Call a function registered as callChangeSentIn in the SWF named myMovie. */
    getMovieName("OneSentenceLogin").callChangeSentIn(sentIn); 

// The following error only happens on the other server:
// Uncaught TypeError: Object #<HTMLEmbedElement> has no method 'callChangeSentIn'

    }
    /* This utility function resolves the string movieName to a Flash object reference based on browser type. */
    function getMovieName(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
    return window[movieName]
    }
    else {
    return document[movieName]
    }
 }

为什么在从另一台服务器调用时找不到方法callChangeSentIn,即使swf仍在加载?

2 个答案:

答案 0 :(得分:0)

尝试始终设置allowScriptAccess。

More info

答案 1 :(得分:0)

这是swf加载时所需要的: 的Security.allowDomain( “www.example.com”) 在我的情况下,我放入

Security.allowDomain("74.52.88.189");
Security.allowDomain("http://74.52.88.189");
Security.allowDomain("http://74.52.88.189/");

不确定哪一个是必要的。

这里也回答了,但我出于某种原因没有找到它。 Flash not being called by Javascript on different domain