IE 中的 Flash 和 JavaScript 通信
我在 IE 使用 Flash CS4 中的 EternalInterface 类将字符串传递回 swf 时遇到问题。
我有一个带有以下代码的 swf:
var externalString:String = ExternalInterface.call("IncomingJS")
它位于附加到 Event.ENTERFRAME 的事件侦听器和等待ExternalInterface.available 的 if 语句中。
IncomingJS
函数如下所示:
function IncomingJS() {
return stringFromHTML;
}
位于带有 swf 的 HTML 页面上。
我能够在 Firefox、Safari 和 Chrome 中成功获取 externalString
变量并继续处理 AS3 脚本的其余部分,但在 IE 中却不行。
如果我在 Javascript 中的 return 语句之前添加一个 alert (stringFromHTML)
,我会得到垃圾邮件 stringFromHTML
的值,看起来 Flash 正在触发该函数正确的利率。
swf 的 HTML 嵌入代码有点简单:
<object width="750" height="200" id="controlledScale"><param name="movie" value="http://www.myURL.com/controlledScale.swf"><param name="allowScriptAccess" value="sameDomain" /><embed src="http://www.myURL.com/controlledScale.swf" width="750" height="200" allowScriptAccess="sameDomain"></embed></object>
任何帮助或建议将不胜感激。
谢谢, DavidB
编辑
我意识到 SWF 嵌入代码有多么糟糕。 不幸的是,HTML 代码实际上是在第 3 方 HTML 生成器中工作的,它的局限性之一是我一次只能有一行(长度不受限制)的 html。
其他选项(swfObject 等)是否能够在代码中不换行的情况下运行,或者我是否会在 Javascript 和 SWF 方面遇到麻烦,而不是直接嵌入 SWF,而是使用 iFrame 之类的东西并引用“正确的”flash部署html文件?
在这一点上,我什至不确定问题实际上出在哪里。 swf 会在所有浏览器中发送到 Javascript,只是不会仅在 IE 中获取信息。
I am having in issue with IE passing a string back into an swf using the EternalInterface class in Flash CS4.
I have an swf with the following code:
var externalString:String = ExternalInterface.call("IncomingJS")
which is inside an event listener attached to an Event.ENTERFRAME and an if statement waiting for ExternalInterface.available.
The IncomingJS
function looks like:
function IncomingJS() {
return stringFromHTML;
}
and sits on the HTML page with the swf.
I am able to successfully get the externalString
variable and procceed with the rest of the AS3 script in Firefox, Safari and Chrome, but not in IE.
If I add in an alert (stringFromHTML)
before the return statement in the Javascript, I get the value of the stringFromHTML
spammed, which looks like Flash is firing the function at the right rate.
The embed code in HTML for the swf is a little simple:
<object width="750" height="200" id="controlledScale"><param name="movie" value="http://www.myURL.com/controlledScale.swf"><param name="allowScriptAccess" value="sameDomain" /><embed src="http://www.myURL.com/controlledScale.swf" width="750" height="200" allowScriptAccess="sameDomain"></embed></object>
Any help or advice would be greatly appreciated.
Thanks,
DavidB
Edit
I realise how poor the SWF embed code is.
Unfortunately, the HTML code is actually working within a 3rd party HTML generator, and one of it's limitations is that I can only have a single line (with unlimited length) of html at a time.
Are the other options (swfObject etc) able to run either with no line breaks in the code, or would I be asking for trouble with Javascript and the SWF to, instead of embedding the SWF directly, use something like an iFrame and refer to a 'proper' flash delpoyment html file?
Kind of at a point on this one where I'm not even sure where the problem is actually located. The swf's are find sending out to Javascript across all browsers, just not getting info back in IE only.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须将
id
添加到对象标记才能在 IE 中工作。You must add an
id
to the object tag to work in IE.我非常确定 IE 中有一个安全“功能”,可以阻止 Flash 多次调用 JS,从而阻止浏览器崩溃。
是否有理由必须每一帧都调用它?
我建议不惜一切代价反对这种做法,因为它会给浏览器带来很大的额外压力。
***** 编辑 *****
如果你想从 JS 调用ExternalInterface方法 ->在 IE 中的 Flash 中,您必须稍微不同地引用该对象,如下所示:
然后,一旦您确定要传递的字符串构造正确,您就可以从 JS 中这样调用它:
然后在 Flash 中,您将得到如下所示的内容:
来自 AS3 文档 的重要内容关于ExternalInterface是这样的:
I pretty sure there is a security "feature" in IE that stops JS being called too many times from Flash, to stop it crashing the browser.
Is there a reason why you have to call it every frame?
I'd suggest against this at all costs as it's putting a LOT of extra stress on the browser.
***** EDIT *****
If you want to call an ExternalInterface method from JS -> Flash in IE you have to reference the object slightly differently, like this:
Then once you're sure the string you want to pass is constructed correctly you can call it like this from the JS:
Then in your Flash you would have something like this:
The standout line from the AS3 docs regarding ExternalInterface is this:
这:
是问题所在。
swf 位于
感谢您的帮助。如果我从这次经历中没有学到任何其他东西,那就是充满问题,超越眼前的问题,尽可能充分地分解每个元素。
This:
is the problem.
The swf is sitting inside a
<form>
tag.At the browser stage, there is a huge volume of really verbose code, and I missed the tags at the very beginning and end of the html code.
Thanks for the help. If I have learnt nothing else from the experience, it's to be full with the question and look well beyond the immediate problem, breaking each element down as fully as I can.