javascript - 页面加载swf对象后添加模拟鼠标左键单击

标签 javascript flash

我在我的网站上添加了一个 Flash 游戏,由于某种原因,加载后需要在页面上的任意位置单击鼠标左键。然后单击即可使箭头键起作用。

我在我的html中尝试了基于js的鼠标触发器,并向我的flash对象添加了一个id,但它仍然不起作用。有什么建议吗?

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Donkey Kong</title>

<script type="text/javascript">
function swfLoadEvent(fn){
//Ensure fn is a valid function
if(typeof fn !== "function"){ return false; }
//This timeout ensures we don't try to access PercentLoaded too soon
var initialTimeout = setTimeout(function (){
    //Ensure Flash Player's PercentLoaded method is available and returns a value
    if(typeof e.ref.PercentLoaded !== "undefined" && e.ref.PercentLoaded()){
        //Set up a timer to periodically check value of PercentLoaded
        var loadCheckInterval = setInterval(function (){
            //Once value == 100 (fully loaded) we can do whatever we want
            if(e.ref.PercentLoaded() === 100){
                //Execute function
                fn();
                //Clear timer
                clearInterval(loadCheckInterval);
            }
        }, 1500);
    }
}, 200);
}
</script>

<script type="text/javascript">
$("document").ready(function() {
setTimeout(function() {
$("#swf").trigger('click');
},5000);
});
</script>

</head>

<style type="text/css">
body, html{
height: 100%;
min-height: 100%;
}
body
{
border: 0px;
padding: 0px;
overflow: hidden;
margin: 0px;
}
object {
border: none;
outline: none;
}  
</style>

<body style="background-color: #000000">

<table class="flash-container" style="height: 94%; width:100%">
    <tr style="height: 100%; width:100%">
        <td style="height: 100%; width:100%">

<script type="text/javascript">             
          //This function is invoked by SWFObject once the <object> has been created
var callback = function (e){

//Only execute if SWFObject embed was successful
if(!e.success || !e.ref){ return false; }

swfLoadEvent(function(){
alert("The SWF has finished loading!");

}); 

};

swfobject.embedSWF("donkey_kong.swf", "flashcontent", "550", "400", "9", false, false, false, false, callback);
</script>            

        </td>
    </tr>
</table>
</body>
</html>

最佳答案

您需要轮询 100% 加载的闪存对象。在这里检查解决方案:

http://learnswfobject.com/advanced-topics/executing-javascript-when-the-swf-has-finished-loading/

编辑: 您当前的函数中包含 HTML。删除 HTML,使其看起来像这样:

swfLoadEvent(function(){
    alert("The SWF has finished loading!");

});

关于javascript - 页面加载swf对象后添加模拟鼠标左键单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39472022/

相关文章:

c# - 是否有可能使这个 Flex/Flash 应用程序安全?

javascript - 我们是否应该将 Flash 作为最后的手段?

javascript - 什么时候真正需要使用 Flash?

Javascript 如何创建一个数组数组

javascript - 使用绝对定位在内容上方显示图像

javascript - 在 Internet Explorer 8 中调整 HTML 对象大小

flash - ActionScript 的椭圆曲线加密

php - 使用 ffmpeg 而不是 flvmdi 将元数据添加到 flv 文件

javascript - 从 DOM 元素集合中获取最高高度值

javascript - 单击事件被激活时引用了错误的对象