Giving keyboard focus to an embedded Flash movie
Issue
A Flash movie embedded in an HTML page does not receive key events when the page first loads in a Web browser.
Reason
In order for a Flash movie to capture key events, the movie itself must first be given focus from the browser. Web browsers do not automatically give keyboard focus to Flash movies, or any other embedded content.
Solution
There are two ways to give focus to the Flash movie.
- Have the user click in the Flash movie Add a button to the first frame of the movie that the user must click in order to continue (an "Enter", "Start" or "Login" button, for example). Any subsequent key presses can be detected by Flash.
- Use JavaScript to give focus to Flash The JavaScript
focus()method can automatically give focus to the Flash movie when the HTML page containing it loads.
Note: This method only works on Windows versions of Internet Explorer.- Open the HTML page containing the Flash movie in an HTML editor (Dreamweaver, for example) or text editor.
- To the <BODY> tag, add an
onLoadhandler that gives focus to the Flash movie, as shown below:<body onLoad="window.document.movieID.focus();">
Make sure thatmovieIDin theonLoadhandler matches the name given to the OBJECT tag used to embed the Flash movie, as shown below.<object classid="..." codebase="...." width=550 height=400 name="movieID">
You can give any name to the OBJECT tag as long as it doesn't contain any spaces or other special characters.
This content requires Flash
To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
Download the free Flash Player now!
