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 interactivity. 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 applicable to all the others.

The following typical user interaction tasks are described in this chapter:

Important concepts and terms

It's important to familiarize yourself with the following key user interaction terms before proceeding:

Working through in-chapter examples

As you're working through the chapter, you may want to test some of the sample code listings for yourself. Because this chapter is about working with user input in ActionScript, essentially all the code listings in this chapter involve manipulating some type of display object--usually a text field or any InteractiveObject subclass. For the purposes of the examples, the display object either can be one that has been created and placed on the Stage in Adobe Flash CS3 Professional, or can be one that's created using ActionScript. Testing a sample involves viewing the result in Flash Player and interacting with the sample to see the effects of the code.

To test the code listings in this chapter:

  1. Create an empty Flash document.
  2. Select a keyframe in the Timeline.
  3. Open the Actions panel and copy the code listing into the Script pane.
  4. Create an instance on the Stage:
  5. Select the text field, button, or movie clip, and give it an instance name in the Property inspector. The name should match the name of the display object in the sample code--for example, if the code manipulates an object named myDisplayObject, name your Stage object myDisplayObject as well.
  6. Run the program using Control > Test Movie.

    On the screen, the display object is manipulated as specified in the code.


Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00000310.html