按下按钮后加载闪光灯

时间:2013-03-30 15:30:42

标签: javascript css flash

我正在与我的学校工作建立一个网站(dreamfoxgames.com)。

如果你点击一个名为“play”的按钮,弹出窗口/ Modal将随flash或unity插件一起出现。我的问题是,当访问者加载页面时,他们将自动加载Flash文件。这意味着音乐将开始,加载时页面将变慢(所有这些游戏)。

有人在点击播放按钮后才能加载Flash播放器吗?

非常感谢!

2 个答案:

答案 0 :(得分:0)

您可以使用swfobject在div中加载swf内容。

假设你的html中有一个div,如下所示

<!DOCTYPE html>
<head>
    <script src="//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script> 
    <script>
</head> 
<body>
      <div id="myContent">
        swf will be embedded here
      </div>
     <button onclick="playSwf()">Click to play swf</button>
</body>
</html>

玩swf ..

 <script type="text/javascript">
    function playSwf()
    {
       //Syntax  
       //swfobject.embedSWF(swfUrl, id, width, height, version,
      //                    expressInstallSwfurl, flashvars, params,
     //                     attributes, callbackFn)

         //optional parameters omitted
         swfobject.embedSWF("test.swf", "myContent", "400", "400","10"); 

    }
    </script>

答案 1 :(得分:0)

也可以使用embed元素(不需要外部api)来完成:

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
    var flashEmbed = null;
    function startFlash() {
    if(flashEmbed != null) {
        document.getElementById("flashContainer").removeChild(flashEmbed);
    }
    flashEmbed = document.createElement("embed");
    document.getElementById("flashContainer").appendChild(flashEmbed);
    flashEmbed.src="Flashfile.swf";
    flashEmbed.type="application/x-shockwave-flash";
    }
</script>
</head>
<body>
<button onclick="startFlash()">start flash</button>
<div id="flashContainer"></div>
</body>
</html>