How to make flash object get focus on loading?

I am trying to set up this test page for my flash game, but it refuses to focus on loading. I read a bunch of posts in the forum and didn’t get anything from him, I can’t believe that it should be so difficult.

Here is what I have:

  <head>
<title>UP HERE WE ESCAPE THE RAT RACE</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script type="text/javascript">
    swfobject.embedSWF("UpHere.swf", "myContent", "700", "300", "9.0.0");

    function setFocusOnFlash() { 
    var fl = document.getElementById("myContent"); 
      if (fl) { fl.focus(); } 
    } 
</script>
  </head>
  <body  onload="setFocusOnFlash()">
  <div style="margin:0 auto; text-align:center; width:700px;">
    <div id="myContent" style="margin:0 auto; text-align:center; width:700px;">
      <p>Alternative content</p>
    </div>
     </div>
      </body>

You can see it here, http://joon.be/exclusivepreview/

what's wrong with him? I do not have very deep knowledge of swfObject ...

+5
source share
4 answers

I found a way that works for me in Firefox 16, Chrome 23, and IE 8 (this is where I have tested it so far). Of course, this is a bunch of hacks, so who knows if this will work forever ... but this, of course, does not worsen the situation.

function setFocusOnFlash() {    
    var flash = document.getElementById("theIdOfTheObjectElement");
    flash.tabIndex = 1234;  // This was needed on Chrome 23
    flash.focus();
    // Attention: FireFox needs wmode "opaque"!
}

Firefox, <param name="wmode" value="opaque"> object , focus() . ( Stephen Belanger jquery.flash, wmode; , SWFObject.)

, setFocusOnFlash . Chrome IE setTimeout(setFocusOnFlash, 1) , JavaScript, , . setFocusOnFlash() . , , , , . Firefox ; object ( ), Flash . 250 , , . (, setFocusOnFlash ... , .) , ExternalInterface.call("flashLoaded") -, , Flash/ActionScript, SWF . , SWF , flashLoaded JavaScript HTML-, , . :

function flashLoaded() {
    // Oddly, directly calling setFocusOnFlash() didn't work on IE8
    setTimeout(setFocusOnFlash, 1);
}
+6

- ExternalInterface Flash JS- (.. Flash). , stage.focus AS , erm, quirks. .

+1

, Flash-, , . , , Chrome.

<body onload='document.getElementById("haxe").focus();'>
    <embed src="game.swf" id="haxe" ...

If you have already tried focus (), and this did not work for you, note that you only need to use the embed tag , not the version of the object and parameter.

Tested on Chrome version 40.0.2214.93 (64-bit).

0
source

All Articles