Automatically focus swf in browser on start
Filed in Coding, 02/07/2010, 21:16 by parheliumRecently I finished site for my friend who set up the band called “nebo“. The aim was to make clean and simple design with one extra feature – browsing their first album “Chwala i czesc” in 3d environment (3d cover). It’s easy to rotate and resize album by using keyboard and mouse scroll. After some attempts and googling, finally I achieve the goal – swf file is focused in browser by javascript in the beginning.
How to gain focus on swf file in any browser on load ?
In your html file put code:
var randomnumber=Math.floor(Math.random()*10000);
var attributes = { id:'frame', name:'frame' };
function setupSWFObjectFocus() {
var swf = document.getElementById("frame");
swf.focus();
}
swfobject.embedSWF("nebo.swf?"+randomnumber,
'frame',
'100%',
'100%',
'10.0.0',
'assets/swfobject/expressinstall.swf',
{},
{ bgcolor: '#000000',
menu: 'false',
allowFullScreen: '},
attributes,
{},
setupSWFObjectFocus
);
In flash file invoke method setupSWFObjectFocus from javascript by using:
import flash.external.ExternalInterface;
...
ExternalInterface.call("setupSWFObjectFocus");
And that’s all.
It’s important to note, that above solution doesn’t require you to use wmode:opaque. You can simply use default value for wmode. My experience is that default (wmode:window) value provides better perfomance than opaque one.