Firefox 的 Flash 外部接口问题
我很难让ExternalInterface 在 Firefox 上运行。 我正在尝试从 javascript 调用 AS3 函数。 SWF 已使用正确的回调进行设置,并且可以在 IE 中运行。
我正在使用 AC_RunActiveContent.js 将 swf 嵌入到我的页面中。 不过,我对其进行了修改,将 ID 添加到对象/嵌入标签中。 下面是分别为 IE 和 Firefox 生成的对象和嵌入标记。
<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="400" height="400" align="middle" id="jpeg_encoder2" name="jpeg_encoder3" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" >
<param name="movie" value="/jpeg_encoder/jpeg_encoder3.swf" />
<param name="quality" value="high" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="scale" value="showall" />
<param name="wmode" value="window" />
<param name="devicefont" value="false" />
<param name="bgcolor" value="#ffffff" />
<param name="menu" value="false" />
<param name="allowFullScreen" value="false" />
<param name="allowScriptAccess" value="always" />
</object>
<embed
width="400"
height="400"
src="/jpeg_encoder/jpeg_encoder3.swf"
quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
align="middle"
play="true"
loop="true"
scale="showall"
wmode="window"
devicefont="false"
id="jpeg_encoder2"
bgcolor="#ffffff"
name="jpeg_encoder3"
menu="false"
allowFullScreen="false"
allowScriptAccess="always"
type="application/x-shockwave-flash" >
</embed>
我正在这样调用该函数...
<script>
try {
document.getElementById('jpeg_encoder2').processImage(z);
} catch (e) { alert(e.message); }
</script>
在 Firefox 中,我收到一条错误消息“document.getElementById("jpeg_encoder2").processImage is not a function
”
有什么想法吗?
I am having a hard time getting ExternalInterface to work on Firefox. I am trying to call a AS3 function from javascript. The SWF is setup with the right callbacks and it is working in IE.
I am using AC_RunActiveContent.js to embed the swf into my page. However, I have modified it to add an ID to the Object / Embed Tags. Below are object and embed tag that are generated for IE and for Firefox respectively.
<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="400" height="400" align="middle" id="jpeg_encoder2" name="jpeg_encoder3" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" >
<param name="movie" value="/jpeg_encoder/jpeg_encoder3.swf" />
<param name="quality" value="high" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="scale" value="showall" />
<param name="wmode" value="window" />
<param name="devicefont" value="false" />
<param name="bgcolor" value="#ffffff" />
<param name="menu" value="false" />
<param name="allowFullScreen" value="false" />
<param name="allowScriptAccess" value="always" />
</object>
<embed
width="400"
height="400"
src="/jpeg_encoder/jpeg_encoder3.swf"
quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
align="middle"
play="true"
loop="true"
scale="showall"
wmode="window"
devicefont="false"
id="jpeg_encoder2"
bgcolor="#ffffff"
name="jpeg_encoder3"
menu="false"
allowFullScreen="false"
allowScriptAccess="always"
type="application/x-shockwave-flash" >
</embed>
I am calling the function like this...
<script>
try {
document.getElementById('jpeg_encoder2').processImage(z);
} catch (e) { alert(e.message); }
</script>
In Firefox, I get an error saying "document.getElementById("jpeg_encoder2").processImage is not a function
"
Any Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
尝试以下两件事:
首先,尝试像这样从 Javascript 调用该函数:
其次,我发现 Firefox 中的ExternalInterface 调用似乎只适用于嵌入标签,而不适用于对象标签。 看看如果您只使用嵌入标签是否可以让它工作。 (现在,我不清楚您发布的 HTML/Javascript 组合是否会访问该对象或嵌入元素。)
Try these two things:
First, try calling the function from Javascript like this:
Second, I've found that ExternalInterface calls in Firefox seem to only work with embed tags, not object tags. See if you can get it to work if you just use an embed tag. (Right now, I'm not clear whether the HTML/Javascript combo you've posted will access the object or the embed element.)
嗯,你是否使用 addCallback 将你的 actionscript 函数暴露给了 Javascript?
有关 addCallback 的 Adobe 文档
Hmm, did you expose your actionscript function to Javascript with addCallback ?
Adobe documentation on addCallback
下面是如何将 Flash 影片放置在 html 页面中的示例。 这部电影是非常简单的电影,开头有一个停止动作。 该电影在下面的“测试运行”主题下显示。 这个特定的 html 代码是由 FlashMX 的 Publish 命令自动生成的。 请注意,Flash 影片文件是 simplemovie.swf; Flash 已自动分配 ID 和名称以匹配电影文件名(减去 .swf 扩展名)。 实际上,名称和 ID 可以是任何东西(但不要使用通俗名称,特别是不要以数字开头),只要它没有被同一页面中的任何其他元素使用即可。
<代码>
`codebase="http://download.macromedia.com/pub/shockwave/cabs/flash`/swflash.cab#version=6,0,0,0"
` WIDTH="150" HEIGHT="75" id="simplemovie" ALIGN="">
<代码>
<代码>
<代码>
<代码>
` 质量=中
` swliveconnect =“真”
` bgcolor=#FFFFFF 宽度=“150” 高度=“75”
` 名称=“简单电影”
` 对齐=""
`TYPE =“应用程序/x-shockwave-flash”
` PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
<代码>
flash 文件中有一个播放函数,以下函数将调用该函数:
Below is an example of how a Flash movie is placed within a html page. This movie is very simple movie with a stop action at the beginning. The movie is shown below under Test Runs subject. This particular html code was auto generated by FlashMX's Publish command. Notice that the Flash movie file is simplemovie.swf; and an id and a name have been assigned automatically by Flash to match the movie filename (minus the .swf extension). In reality, the name and id could be anything (but do not use exoteric names, especially, do not start with a number), as long as it has not been used by any other element in the same page.
`codebase="http://download.macromedia.com/pub/shockwave/cabs/flash`/swflash.cab#version=6,0,0,0"
` WIDTH="150" HEIGHT="75" id="simplemovie" ALIGN="">
` quality=medium
` swliveconnect="true"
` bgcolor=#FFFFFF WIDTH="150" HEIGHT="75"
` name="simplemovie"
` ALIGN=""
`TYPE="application/x-shockwave-flash"
` PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
there is a play function in the flash file the following function will calls that function:
请参阅此帖子。
您需要一个更像这样的 JS 函数来检索 Flash 对象(而不是 getElemById):
并确保在加载文档之前不要调用此函数。
See this post.
You want a JS function more like this to retrieve the Flash object (rather than getElemById):
And make sure not to call this function until the document is loaded.
尝试在 object 和 embed 标记中使用相同的 ID。 我记得一个浏览器使用一个标签,另一个浏览器使用另一个......不知道哪个是哪个。 我前段时间也遇到过同样的问题。
我通过修改 示例代码 自带闪光灯。 确保它能工作,然后将其剥离并进行调整以供我使用。
在示例中,请注意 object 标记的 id 设置为“ExternalInterfaceExample”,然后 embed 标记的 name > 参数也设置为“ExternalInterfaceExample”。 我想这可能是你的线索。
祝你好运!
Try having the same id in both object and embed tags. I remember one browser is using one tag and another browser the other...don't know which one is which. I had the same issue some time ago.
I'm got around by modifying the Example Code that comes with flash. Making sure it works, then stripping it down and adapting it for my use.
In the example notice that the object tag the id set to "ExternalInterfaceExample", then the embed tag has the name parameter set to "ExternalInterfaceExample" as well. I think that might be your clue.
Good luck!
在尝试调用它们之前,您的 swf 是否可见(在页面上)? 如果没有,请阅读以下内容: swf-直到可见才初始化
Are your swf's visible (on the page) before you try calling them? If not, read this: swf-not-initializing-until-visible
如果您不使用 AC_RunActiveContent.js 来嵌入 Flash 影片,而是使用 swfobject,则有一种简单的内置方法可以实现这一点。
如果您不使用 swfObject,您可以直接将 swfobject.getObjectById 复制并粘贴到您的代码中:
If instead of using AC_RunActiveContent.js to embed your flash movie you use swfobject there is a easy build-in way of doing that.
If you are not using swfObject you could just copy and paste swfobject.getObjectById straight in to your code: