Chapter 21. Interactivity with the Mouse and Keyboard
FEATURED CLASSES
flash.events.MouseEventflash.events.KeyboardEventflash.events.FocusEventflash.events.ContextMenuEventflash.display.InteractiveObjectflash.ui.Mouseflash.ui.MouseCursorflash.ui.Keyboardflash.ui.ContextMenuflash.system.IME
The one consistent interface between most people and their computers is, as you know, the keyboard and mouse. Because you can use Flash Player for so many different kinds of applications, it has a flexible model for capturing the user's mouse and keyboard input. You can do anything from simply capturing clicks on buttons to accepting complex mouse gestures. Flash Player's input handling is closely tied to its event model and the display list. All mouse and keyboard input are available to ActionScript 3.0 code as events of type MouseEvent or KeyboardEvent. In this chapter, you'll learn how mouse and keyboard events are handled in general, investigate the various kinds of events Flash Player exposes, and see a variety of real-world input handling code. I'll also cover the focus model in Flash Player and creating custom context menus.
Mouse and Keyboard Event Handling
Every InteractiveObject can dispatch events when interacted with using the keyboard and mouse. This, of course, applies to the subclasses of InteractiveObject, which includes all TextFields, Sprites, Loaders, and the Stage; but not Bitmaps or Shapes.
You'll learn how to listen and respond to these events, determine which events are available, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access