Author Topic: HOW-TO: Automatically Focus the flash object when the page loads  (Read 4388 times)

nitram_cero (2bam)

  • Contributor
  • ****
  • Posts: 484
  • Karma: +0/-0
    • View Profile
    • 2BAM
If you're using swfobject like myself, do like this:

Quote
...
<head>

   <script src="js/swfobject.js" type="text/javascript"></script>
   <script type="text/javascript">
      var flashvars = {
      };
      var params = {
         menu: "false",
         scale: "noScale",
         allowFullscreen: "true",
         allowScriptAccess: "always",
         bgcolor: "#000000"
      };
      var attributes = {
         id:"flashObject"
      };
      swfobject.embedSWF("flashgame.swf", "flashAltContent", "800", "600", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
   </script>

</head>
<body bgcolor="#000000" onLoad="document.getElementById('flashObject').focus();">

...

If you're using the straight dope, do like this:
Quote
<body bgcolor="#000000" onLoad="document.getElementById('flashObject').focus();">
...
<object id="flashObject" width="800" height="600" type="application/x-shockwave-flash" data="flashgame.swf">

And you can start playing right away, without having to click on the game to start.

Regards!
« Last Edit: Tue, Dec 15, 2009 by nitram_cero »

BullitSpeed

  • Contributor
  • ****
  • Posts: 264
  • Karma: +0/-0
    • View Profile
    • My Website!
Awesome.  Beer for you!

Adam Atomic

  • Founder
  • Key Contributor
  • *****
  • Posts: 852
  • Karma: +0/-0
  • new dad
    • View Profile
    • Adam Atomic
oh nice one :D

nitram_cero (2bam)

  • Contributor
  • ****
  • Posts: 484
  • Karma: +0/-0
    • View Profile
    • 2BAM
Thanks... I'll put it on the wiki.

CosMind

  • Member
  • **
  • Posts: 6
  • Karma: +0/-0
  • stuff 'n stuff
    • View Profile
    • Glum Buster
tapping in to this will make me happy - but, pardon my ignorance, where exactly do we place this code?

nitram_cero (2bam)

  • Contributor
  • ****
  • Posts: 484
  • Karma: +0/-0
    • View Profile
    • 2BAM
Somewhere in your page's HTML

inside the head / body tags (as shown in the example)

Regards

TheBear

  • New Member
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
To make this work on Safari and Chrome you need to do this:
Quote
<body onLoad="var f = document.getElementById('flashObject'); f.tabIndex = 0; f.focus();">