0

I've added a flash game to my site that for some reason requires a left mouse click anywhere on the page after it loads. The click then enables the arrow keys to work.

I've tried a js based mouse trigger in my html and added an id to my flash object, but it's still not working. Any advice?

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 Answer 1

1

You need to poll for 100 percent loaded flash object. Check the solution here:

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

EDIT: Your current function has HTML in it. Remove the HTML so it looks like this:

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

});
Sign up to request clarification or add additional context in comments.

6 Comments

I have revised the script, but now I get a blank page! Please see revised script above.
You have HTML inside your function. swfLoadEvent(function(){ <object id="swf" width="100%" height="100%"> <param name="autoPlay" value="true"></param> <embed allowfullscreen="true" autoPlay="true" allownetworking="all" allowscriptaccess="always" height="100%" src="images/games/donkey_kong.swf" type="application/x-shockwave-flash" width="100%"></embed> </object> alert("The SWF has finished loading!"); });
Sorry, but I don't understand. Can you revise script?
Revised script based on your suggestion...still not working. See OP above.
Are you getting a console error? Can you try to console.log the e.ref.PercentLoaded() ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.