我正在尝试使用 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 仍在加载?