IE 中的 Flash 和 JavaScript 通信

发布于 2024-09-11 02:14:31 字数 1404 浏览 4 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

﹉夏雨初晴づ 2024-09-18 02:14:31

您必须将 id 添加到对象标记才能在 IE 中工作。

<object width="750" id="myflash" height="200"><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>

You must add an id to the object tag to work in IE.

<object width="750" id="myflash" height="200"><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>
最美不过初阳 2024-09-18 02:14:31

我非常确定 IE 中有一个安全“功能”,可以阻止 Flash 多次调用 JS,从而阻止浏览器崩溃。

是否有理由必须每一帧都调用它?

我建议不惜一切代价反对这种做法,因为它会给浏览器带来很大的额外压力。

***** 编辑 *****

如果你想从 JS 调用ExternalInterface方法 ->在 IE 中的 Flash 中,您必须稍微不同地引用该对象,如下所示:

function thisMovie(movieName) {
  if (navigator.appName.indexOf("Microsoft") != -1) {
    return window[movieName];
  } else {
    return document[movieName];
  }
}

然后,一旦您确定要传递的字符串构造正确,您就可以从 JS 中这样调用它:

thisMovie( "theFlashElementID" ).giveMeMyStringAlready();

然后在 Flash 中,您将得到如下所示的内容:

if( ExternalInterface.available ) 
{
  ExternalInterface.addCallback( "giveMeMyStringAlready", handleTheStringFromJS );
}
  else
{
  handleTheFactIDontHaveExternalInterfaceAvailable();
  // the only reason this would be is if container that 
  // is embedding the swf isn't fully loaded by the browser
}

来自 AS3 文档 的重要内容关于ExternalInterface是这样的:

注意:当使用外部 API 时
HTML,始终检查 HTML 是否具有
在您尝试之前已完成加载
调用任何 JavaScript 方法。

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:

function thisMovie(movieName) {
  if (navigator.appName.indexOf("Microsoft") != -1) {
    return window[movieName];
  } else {
    return document[movieName];
  }
}

Then once you're sure the string you want to pass is constructed correctly you can call it like this from the JS:

thisMovie( "theFlashElementID" ).giveMeMyStringAlready();

Then in your Flash you would have something like this:

if( ExternalInterface.available ) 
{
  ExternalInterface.addCallback( "giveMeMyStringAlready", handleTheStringFromJS );
}
  else
{
  handleTheFactIDontHaveExternalInterfaceAvailable();
  // the only reason this would be is if container that 
  // is embedding the swf isn't fully loaded by the browser
}

The standout line from the AS3 docs regarding ExternalInterface is this:

Note: When using the External API with
HTML, always check that the HTML has
finished loading before you attempt to
call any JavaScript methods.

四叶草在未来唯美盛开 2024-09-18 02:14:31

这:

不幸的是,HTML 代码是
实际上在第三方工作
HTML 生成器

是问题所在。

swf 位于

标记内。
在浏览器阶段,有大量非常冗长的代码,而且我错过了 html 代码开头和结尾的标签。

感谢您的帮助。如果我从这次经历中没有学到任何其他东西,那就是充满问题,超越眼前的问题,尽可能充分地分解每个元素。

This:

Unfortunately, the HTML code is
actually working within a 3rd party
HTML generator

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文