偶发的“SetVariable 不是函数”在火狐浏览器中
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
错误 .SetVariable is not a function in Firefox 的一种解决方案是
Give Id &名称属性的值与对象标记的 id 和 name 值不同。
确保在文档完全加载后调用 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.
Make sure LoadRefference is called after document is fully loaded.you can call it in document.ready method
Muhammad Khalid Noor
您应该使用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?
我不知道 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?