使用swfobject自动启动swf视频

时间:2013-08-30 13:49:00

标签: javascript html swfobject autoplay

我点击图片后会加载视频,问题是视频无法自动播放,因此您必须点击两次。我想点击图片时自动播放此视频。提前致谢

<tr>
    <td class="filmbodyplay" height="50" align="right" valign="top">
      <a href="#" onclick="playMovie( this, 'https://www.capcomfcu.org/images/stories/security-center/swf/phishing.swf' );" >
            <img src="https://www.capcomfcu.org/images/stories/security-center/phishing.jpg" border="0" alt="play" />
      </a>
    </td>
</tr>
<script type="text/javascript">
swfobject.registerObject("FlashID");
</script>

标题代码

<script src="Scripts/swfobject_modified.js" type="text/javascript"></script>
<script type="text/javascript">
function playMovie( a, href ) {

    // remove element if exists
    var container   = document.getElementById( "playing" );
    var flash_movie = document.getElementById( "flash_movie" );

    if( flash_movie ) {
        container.removeChild( flash_movie );
    }   

    // create new element
    var embed = document.createElement( "EMBED" );
    embed.setAttribute( "allowFullScreen", "true" );
    embed.setAttribute( "autostart", "true");
    embed.setAttribute( "src", href );
    embed.setAttribute( "type", "application/x-shockwave-flash" );
    embed.setAttribute( "width", "480" );
    embed.setAttribute( "height", "360" );
    embed.setAttribute( "id", "flash_movie" );

    // clear out the cell
    cell = a.parentNode;
    cell.id = 'playing';

    while( cell.hasChildNodes() ) {
        cell.removeChild( cell.firstChild );
    }

    // insert the element into the cell
    cell.appendChild( embed );

}


</script>

1 个答案:

答案 0 :(得分:0)

在使用embed标签时,看起来在加载时立即开始播放的属性是 play http://helpx.adobe.com/flash/kb/flash-object-embed-tag-attributes.html),但默认为true。我想知道你的swf是否在主时间轴中有一个加载器,在这种情况下你需要放置一些动作脚本来自动开始播放。