In this example, a movie clip called myarrow_mc is moved 5 pixels to the right. Within the function, Flash checks to see if the key that was pressed matches the right-arrow When you press a key, Flash dispatches a KeyboardEvent object and calls the function. Choose File > Publish Preview > Default.If they are equivalent, the actions within the curly braces of the if statement are executed. The double equals symbol ( =) checks the equivalence of the items on either side. Next, create a function with a KeyboardEvent parameter:įunction detectText(myevent:KeyboardEvent):void Stage.addEventListener(KeyboardEvent.KEY_DOWN, detectText) You can detect and respond to the KeyboardEvent object by first attaching a listener to the main Stage (or another object like a text field) using the addEventListener method as follows: Just as a MouseEvent object is created when the user does something with the mouse, a KeyboardEvent object (another subclass of the Event class) is created when the keyboard is used. (like the Ctrl or Shift key) that trigger a response. Flash even lets you control live text that the viewer types in empty text fields in a movie these text fields meritĪ separate discussion in Chapter 10, “Controlling Text.” This section focuses on single or combination keystrokes with modifiers Keyboard (using the arrow keys or the number keys, for example) or having keyboard shortcuts that duplicate mouse-based navigation This ability opens the possibility of having navigation based on the The keyboard is just as important an interface device as the mouse, and Flash lets you detect events occurring from keystrokes,īoth the downward keypress and the upward key release. Flash Professional CS5 Advanced for Windows and Macintosh: Visual QuickPro Guide