Chapter 21. Interactivity with the Mouse and Keyboard
FEATURED CLASSES
flash.events.MouseEvent
flash.events.KeyboardEvent
flash.events.FocusEvent
flash.events.ContextMenuEvent
flash.display.InteractiveObject
flash.ui.Mouse
flash.ui.MouseCursor
flash.ui.Keyboard
flash.ui.ContextMenu
flash.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 TextField
s, Sprite
s, Loader
s, and the Stage
; but not Bitmap
s or Shape
s.
You'll learn how to listen and respond to these events, determine which events are available, ...
Get ActionScript 3.0 Bible now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.