【问题标题】:Flash not being called by Javascript on different domain不同域上的 Javascript 未调用 Flash
【发布时间】:2012-11-07 22:15:52
【问题描述】:

我正在尝试使用 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"
);

以下是当它是另一台服务器上的 html 页面的一部分时失败的 javascript 代码。 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 仍在加载?

【问题讨论】:

    标签: javascript html flash apache-flex


    【解决方案1】:

    尝试将 allowScriptAccess 设置为 always。

    More info

    【讨论】:

    • 这似乎不起作用。我已将 html 文件更改为 AC_FL_RunContent( "src", "eyespeakpro.com/OneSentenceLogin.swf", "width", "100%", "height", "80%", "align", "middle", "id", " OneSentenceLogin”、“质量”、“高”、“bgcolor”、“#ffffff”、“名称”、“OneSentenceLogin”、“allowScriptAccess”、“always”、“type”、“application/x-shockwave-flash”、 "插件页面", "adobe.com/go/getflashplayer" );然而它没有区别。我是否也应该更改 crossdomain.xml 文件,如果是这样怎么办?
    【解决方案2】:

    这是加载 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

    【讨论】:

    • 使用 allowDomain 和 allowInsecureDomain。您的第二次和第三次调用实际上是对allowInsecureDomain 的间接调用,因为您使用 HTTP 传入了一个 url,但您应该更喜欢显式调用。你应该需要的是Security.allowDomain(x); Security.allowInsecureDomain(x);
    猜你喜欢
    • 1970-01-01
    • 2012-01-19
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-08
    • 2020-12-26
    相关资源
    最近更新 更多