javascript 使用 jQuery 更新 flashvars 并重新加载 flash

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3861517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 02:29:21  来源:igfitidea点击:

Update flashvars and reload flash with jQuery

javascriptjqueryinternet-explorer-8flash

提问by Daniel O

I would like to update the flashvars value argument to view another video:

我想更新 flashvars 值参数以查看另一个视频:

<param name='flashvars' value='movieId=1002' />

I found out that I can make it work in Firefox by updating the parameter with the extra step of readding the whole flash contents.

我发现我可以通过使用读取整个 Flash 内容的额外步骤更新参数来使其在 Firefox 中工作。

$("param[name=flashvars]").attr("value", "movieId=33");
$("embed").attr("flashvars", "movieId=33");
$(".root").append($("#video"));

But this does not work in IE8 as the browser won't refresh the flash contents. Any ideas on how to reload the flash contents without external dependencies like swfobject.js?

但这在 IE8 中不起作用,因为浏览器不会刷新 Flash 内容。关于如何在没有外部依赖项(如 swfobject.js)的情况下重新加载 Flash 内容的任何想法?

采纳答案by PatrickS

Instead of using flashvars, you could use the ExternalInterface AS3 class to send the new value to Flash.

您可以使用 ExternalInterface AS3 类将新值发送到 Flash,而不是使用 flashvars。

ExternalInterface allows for a two way communication between AS3 & Javascript

ExternalInterface 允许 AS3 和 Javascript 之间的双向通信

回答by cloakedninjas

// update flashvars
var fv = 'foobar=1';

$("object param[name='flashvars']").attr("value", fv);
$("embed").attr("flashvars", fv);

// create new object to hold it     
var obj = $("object");

// remove existing Flash from DOM
$("object").remove();

// add new HTML to DOM
$("#mviewer").append(obj.html());

回答by Benjamin Allison

I'm curious about this too. I'm trying to send a new string via flashvars to a SWF that I have no opportunity to change, and just changing the flashvars with jQuery, without having to use externalinterface, is the best option.

我也对这个很好奇。我正在尝试通过 flashvars 将新字符串发送到我没有机会更改的 SWF,只需使用 jQuery 更改 flashvars,而不必使用外部接口,是最好的选择。

回答by matthewwithanm

If you want to change the flash vars and reload the Flash, you should just remove the SWF from the DOM and embed it again with your new vars (using SWFObject or whatever other method suits your fancy!).

如果您想更改 Flash 变量并重新加载 Flash,您只需从 DOM 中删除 SWF,然后将其重新嵌入到新的变量中(使用 SWFObject 或任何其他适合您的方法!)。

If you want to change the flash vars without reloading the Flash, you're out of luck: there's no officially-supported way. In this case, you should use ExternalInterfaceto call ActionScript methods that update your values from JavaScript.

如果您想在不重新加载 Flash 的情况下更改 Flash 变量,那您就不走运了:没有官方支持的方法。在这种情况下,您应该使用ExternalInterface调用从 JavaScript 更新您的值的 ActionScript 方法。

回答by Natim

Actually, why not use swfobject.js ?

实际上,为什么不使用 swfobject.js ?

I did like this :

我是这样的:

   <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
   <script type="text/javascript" src="js/swfobject.js"></script>

   <div id="qsound"></div>

<script type="text/javascript">
   if(q.sound) {
    swfobject.embedSWF("js/dewplayer/dewplayer.swf", "qsound", "60", "20", "9.0.0", false, {'mp3': 'sounds/'+q.sound}, {'wmode': 'transparent'});
    $('#qsound').show();
} else {
    $('#qsound').hide();
}
</script>