偶发的“SetVariable 不是函数”在火狐浏览器中

发布于 2024-08-03 23:20:01 字数 724 浏览 5 评论 0原文

我正在使用 swfObject 在我的应用程序中嵌入 Flash 播放器。有时,当我尝试与嵌入式 Flash 对象通信时,我会在 FireFox 中看到错误(仅在 IE 或 Chrome 中没有)。该错误显示“SetVariable 不是函数”。导致此错误的代码刚才执行得很好,现在显示了此错误。如果我重新加载页面并重新运行,这种情况很可能不会再次发生。

我在网上看到过有关 FF 与 SetVariable 配合不好的报道,但没有任何解决办法。显然 swfObject 应该隐藏所有这些,但事实并非如此。

我的代码如下所示:

...
var flashvars=...
var params=...
var attributes = {};
attributes.id = "my_player";

if( swfobject.hasFlashPlayerVersion("9.0.0") )
{
    swfobject.embedSWF("my_player_js.swf", "my_player_holder", "1", "1", "9.0.0", "", flashvars, params, attributes );
}
....

document.getElementById("my_player").SetVariable( "method:stop", "");

最后一行,在 FF 上,有时会导致“SetVariable 不是函数”错误。

关于去哪里看有什么建议吗?

I'm using swfObject to embed a flash player in my app. Sporadically, I see errors in FireFox (only, not in IE or Chrome) when trying to communicate with the embedded flash object. The error says "SetVariable is not a function". The code which causes this error executed fine just moments ago, and now shows this error. If I re-load the page and re-run, odds are decent that this doesn't happen again.

I've seen reports on the web about FF not working well with SetVariable, but nothing to fix it. Apparently swfObject should hide all of this but it doesn't.

Here's what my code looks like:

...
var flashvars=...
var params=...
var attributes = {};
attributes.id = "my_player";

if( swfobject.hasFlashPlayerVersion("9.0.0") )
{
    swfobject.embedSWF("my_player_js.swf", "my_player_holder", "1", "1", "9.0.0", "", flashvars, params, attributes );
}
....

document.getElementById("my_player").SetVariable( "method:stop", "");

That last line, on FF, sometimes causes the "SetVariable is not a function" error.

Any suggestions on where to look?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

黎歌 2024-08-10 23:20:01

错误 .SetVariable is not a function in Firefox 的一种解决方案是

Give Id &名称属性的值与对象标记的 id 和 name 值不同。

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
var bannerObj = isInternetExplorer ? document.all.banner : document.banner;
function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }

}

function LoadRefference()
{
 bannerObj = getFlashMovieObject("banner");
 if(typeof(bannerObj.SetVariable)=='undefined')
    bannerObj = document.getElementById('embbanner');
}

确保在文档完全加载后调用 LoadReference。您可以在 document.ready 方法

Muhammad Khalid Noor中调用它

One solution for the error .SetVariable is not a function in Firefox is

Give Id & Name attributes a different values than Object tag's id and name values.

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
var bannerObj = isInternetExplorer ? document.all.banner : document.banner;
function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }

}

function LoadRefference()
{
 bannerObj = getFlashMovieObject("banner");
 if(typeof(bannerObj.SetVariable)=='undefined')
    bannerObj = document.getElementById('embbanner');
}

Make sure LoadRefference is called after document is fully loaded.you can call it in document.ready method

Muhammad Khalid Noor

橘香 2024-08-10 23:20:01

您应该使用ExternalInterface,它比SetVariable更健壮(速度较慢,但​​除非您确实需要速度,否则应该使用它)

通常导致此问题的一种常见情况是尝试在之前调用SetVariable swf 已加载。一般来说,在尝试调用方法之前,让 swf 调用页面并告诉 js 它已准备好接收调用会更安全。

既然你说“导致此错误的代码刚刚执行得很好”,这让我认为上述内容可能不是你的问题,但无论如何都值得检查。也许如果您正在修改页面上的 swf,浏览器会尝试重新加载它,这会导致它一次消失几毫秒?

You should use ExternalInterface instead, it's much more robust than SetVariable (slower, but unless you really need the speed, you should use it)

One common case that usually causes this is trying to call the SetVariable call before the swf is loaded. Generally it's safer to have your swf call out to the page and tell the js that it's ready to receive calls before you try and call methods.

Since you say that the 'The code which causes this error executed fine just moments ago' it makes me think that the above may not be your issue, but it is worth checking anyway. Perhaps if you are modifying the swf on the page, the browser is trying to reload it, and that causes it to go away for a few milliseconds at a time?

萌无敌 2024-08-10 23:20:01

我不知道 swfObject 或 Flash,但如果在对象初始化之前在对象上运行代码,通常会发生类似的错误。是什么触发您的代码运行?加载? DOM 内容已加载?

I don't know swfObject or Flash, but errors similar to these often happen if you run code on an object before it has been initialised. What triggers your code to run? onload? DOMContentLoaded?

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