The web site for Flash ActionScript 3.0 game developers

 
         
   

Keyboard Focus

I've been asked by several people over the last few months about keyboard focus for Flash games running in the browser. Usually, the person asking is quite sure what is going on. All they know is that the game doesn't work when the browser first loads it, at least until they click on the game. Then it works.
What is happening here is simply a matter of keyboard focus. When a game, or any Flash movie, loads in a browser the focus of the keyboard is still on the browser. The "focus" simply refers to where the key presses trigger events. So if the browser has keyboard focus, then the browser gets key presses for filling in form fields, entering URLs or search box contents, or executing keyboard shortcuts.
If the user presses the up arrow, for instance, the browser gets that key press and probably tries to scroll up on the page. The Flash movie on the page never even hears about the up arrow being pressed.
To switch the keyboard focus to the Flash movie, the user simply needs to click on the Flash movie. This is the same for anything in a modern OS. If the user clicks on a Finder/Explorer window, then the keyboard focus switches to that. If they click on a word processing window, then the keyboard focus switches to that, etc.
Now, you can also perform some embed/object tag and JavaScript mojo to set the keyboard focus. But that is going overboard. You can simply make sure that the user clicks on your game by including a splash screen and a "start game" or "play" or "begin" button. That's good design anyway, as you don't want most games to start the minute the page loads.


FlashGameU.com Video Tutorial: Catching Game Part 2

Gary Rosenzweig builds a catching game in Flash ActionScript 3.0. In this part, you learn how to have a bucket move with the cursor at the bottom of the screen and catch objects. Some are good and some are bad, and the score changes based on what type of object is caught. You can find full resolution video and more podcasts at FlashGameU.com.

View video at Blip.TV.

Download QuickTime Movie.

Subscribe via iTunes.

Download the source code (final game, parts 1 and 2).

FlashGameU.com Video Tutorial: Catching Game Part 1

Gary Rosenzweig builds a catching game in Flash ActionScript 3.0. In this part, you learn how to have objects fall from the top of the screen, taken from various movie clips in the library using arrays of strings to determine which movie clip is created and dropped.

View video at Blip.TV.

Download QuickTime Movie.

Subscribe via iTunes.

Download the source code (final game, parts 1 and 2).

FlashGameU.com Video Tutorial: Communication Between Movie Clips

Gary Rosenzweig looks at ways movie clips can communicate with each other in Flash ActionScript 3.0.

View video at Blip.TV.

Download QuickTime Movie.

Subscribe via iTunes.

FlashGameU.com Video Tutorial: Understanding the Display List

Gary Rosenzweig talks about display lists and how you can manipulate them to move display elements ahead or behind others.

View video at Blip.TV.

Download QuickTime Movie.

Download the source file.

Subscribe via iTunes.

FlashGameU.com Video Tutorial: Dynamic Filter Effects

Gary Rosenzweig shows you how to apply dynamic filter effects to a movie clip, such as glows, drop shadows and bevels. You can find the source files, full resolution video, and more podcasts at FlashGameU.com.

View video at Blip.TV.

Download QuickTime Movie.

Download the source file.

Subscribe via iTunes.

FlashGameU.com Video Tutorial: Pausing and Resuming Sound

Gary Rosenzweig, author of ActionScript 3.0 Game Programming University, shows you how to pause a sound in AS3 by recording the position of the sound before stopping it, then resuming the sound at that same position.

View video at Blip.TV.

Download QuickTime Movie.

Download the source file.

Subscribe via iTunes.

FlashGameU.com Video Tutorial: Game Inventory System

GGary Rosenzweig looks at a basic game inventory system created with Flash ActionScript 3. Using an Inventory object, you can allow the player to add items to their game inventory. Then you can let them click on the items to use them, or test the inventory contents to allow them to complete tasks in the game.

View video at Blip.TV.

Download QuickTime Movie.

Download the source file.

Subscribe via iTunes.

FlashGameU.com Video Tutorial: Simple Particle System

Gary Rosenzweig, author of ActionScript 3.0 Game Programming University, shows you how to create a very simple particle system using a class and by adding and removing movie clips from the display list.

View video in your browser.

Download QuickTime Movie.

Download the source file.

Subscribe via iTunes.

FlashGameU.com Video Tutorial: Continuous Animation

Gary Rosenzweig, author of ActionScript 3.0 Game Programming University, answers a question in this podcast of how to maintain continuous animation while receiving user input. The character on the screen continues to follow a walk animation even while the player triggers the animation over and over.

View video in your browser.

Download QuickTime Movie.

Download the source file.

Subscribe via iTunes.

Syndicate content

Copyright Gary Rosenzweig