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

时间:2016-09-13 14:02:33

标签: 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>

1 个答案:

答案 0 :(得分:1)

您需要轮询100%加载的Flash对象。检查解决方案:

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

编辑: 您当前的函数中包含HTML。删除HTML,使其如下所示:

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

});