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.
    1. Open the HTML page containing the Flash movie in an HTML editor (Dreamweaver, for example) or text editor.
    2. To the <BODY> tag, add an onLoad handler that gives focus to the Flash movie, as shown below: <body onLoad="window.document.movieID.focus();"> Make sure that movieID in the onLoad handler 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.

Keywords: focus; keypress; key press; active window; make active; tn_15586

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy