无法使用object tag / swfobject在HTML中嵌入flash

时间:2013-06-23 03:02:42

标签: html flash embed swfobject

我正在试图将一个Flash文件嵌入到页面中,并尝试了以下两种方式的多种变体:

swfobject的

<head>
  <%= javascript_include_tag 'swfobject.js' %>
</head>
.
.
.
<div id="dragndrop">This requires Adobe Flash to view</div>
<script type="text/javascript">
  var flashvars;
  var params = {
    movie: "<%= asset_path('flash/drag-n-drop-w-action3b.swf') %>",
    background: "#FFFFFF",
    quality: "high"
  };

  swfobject.embedSWF("<%= asset_path('flash/drag-n-drop-w-action3b.swf') %>",
    "dragndrop", "100%", "100%", "6.0.0", false, params);
</script>

导航到页面不会产生任何结果,但会在浏览器中输出以下内容:

<object id="dragndrop" width="100%" height="100%" type="application/x-shockwave-flash"       
    data="/assets/flash/drag-n-drop-w-action3b.swf" style="visibility: visible;">
  <param name="flashvars" value="movie=/assets/flash/drag-n-drop-w-action3b.swf&background=#FFFFFF&quality=high">
</object>

我已经尝试过没有参数,但也无济于事。

我还尝试过多种方式手动添加它,包括here所述。这个flash文件目前已成功嵌入到不同的网站上,我甚至在那里复制粘贴了html(修复路径):

<object width="100%" height="100%" align="" 
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" 
    classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
  <param value="assets/flash/drag-n-drop-w-action3b.swf" name="movie">
  <param value="high" name="quality">
  <param value="#FFFFFF" name="bgcolor">
  <embed width="100%" height="100%" align="" 
    pluginspage="http://www.macromedia.com/go/getflashplayer" 
    type="application/x-shockwave-flash" bgcolor="#FFFFFF" quality="high"    
    src="/assets/flash/drag-n-drop-w-action3b.swf">
</object> 

我做错了什么?

修改

在pipwerks帮助之后,我将代码更改为:

var params = { background: "#FFFFFF",};
swfobject.embedSWF("<%= asset_path('flash/drag-n-drop-w-action3b.swf') %>", "dragndrop", "100%", "100%", "6.0.0", false, false, params);

然而,它仍然没有完全奏效。输出的新HTML如下:

<object id="dragndrop" width="100%" height="100%" type="application/x-shockwave-flash" 
    data="/assets/flash/drag-n-drop-w-action3b.swf" style="visibility: visible;">
  <param name="background" value="#FFFFFF">
</object>

1 个答案:

答案 0 :(得分:0)

对于初学者,您不小心将参数作为flashvars传递。

其次,您不需要传递大部分参数,因为它们已经被处理掉了。 movie param是SWFObject中的第一个参数。 quality=high是Flash Player的默认设置,无需指定。我相信#FFFFFF也是默认的背景颜色,但指定它并没有什么坏处。

正确的参数顺序是:

swfobject.embedSWF([swf file], 
                   [document element id], 
                   [width], 
                   [height], 
                   [min Flash Player version], 
                   [express install swf or false], 
                   [flashvars obj or false], 
                   [params obj or false], 
                   [attributes obj or false], 
                   [callback function or false]);

因此,您的代码应为:

var params = { background: "#FFFFFF",};
swfobject.embedSWF("<%= asset_path('flash/drag-n-drop-w-action3b.swf') %>", "dragndrop", "100%", "100%", "6.0.0", false, false, params);

有关swfobject参数的详细信息,请参阅this page