450
Chapter 22: Capturing user input
This chapter describes how to create interactivity by using ActionScript™ 3.0 to respond to user activity. It discusses
keyboard and mouse events, and then proceeds to more advanced topics, including customization of the context
menu and focus management. This chapter concludes with WordSearch, an example of an application that responds
to mouse input.
Note that this chapter assumes that you are already familiar with the ActionScript 3.0 event model. For more infor-
mation, see “Handling events” on page 227.
Contents
Basics of user input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
Capturing keyboard input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
Capturing mouse input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
Example: WordSearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
Basics of user input
Introduction to capturing user input
User interaction, whether by keyboard, mouse, camera, or a combination of these devices, is the foundation of inter-
activity. In ActionScript 3.0, identifying and responding to user interaction primarily involves listening to events.
The InteractiveObject class, a subclass of the DisplayObject class, provides the common structure of events and
functionality necessary for handling user interaction. You do not directly create an instance of the InteractiveObject
class. Instead, display objects such as SimpleButton, Sprite, TextField, and various Flash and Flex components inherit
their user interaction model from this class and therefore share a common structure. This means that the techniques
you learn and the code you write to handle user interaction in an object derived from InteractiveObject are appli-
cable to all the others.
The following typical user interaction tasks are described in this chapter:
Capturing application-wide keyboard input
Capturing keyboard input to a specific display object
Capturing application-wide mouse actions
Capturing mouse input to a specific display object
Creating drag-and-drop interactivity
Creating a custom mouse cursor (mouse pointer)
Adding new behaviors to the context menu
Managing focus
Important concepts and terms
Its important to familiarize yourself with the following key user interaction terms before proceeding:

Get ADOBE® FLEX® 3: PROGRAMMING ACTIONSCRIPT™ 3.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.