Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

21.6. Summary

  • ActionScript's event system handles mouse and keyboard events, as instances of MouseEvent and KeyboardEvent.

  • Mouse events set their target to the topmost, visible, nonempty InteractiveObject that responds to mouse input.

  • Keyboard events set their target to the focused object.

  • Both mouse and keyboard events bubble and can be canceled.

  • Listen to stage to get all mouse or keyboard events regardless of mouse position and focus.

  • mouseEnabled, mouseChildren, tabEnabled, and tabChildren properties make the display object invisible to or opaque to mouse and focus events.

  • Single clicks and double clicks dispatch their own events, although double clicks require doubleClickEnabled to be set.

  • Mouse events carry information about the position of the cursor with them, as well as any keyboard modifier keys that were held down.

  • Use startDrag() and stopDrag() along with the MOUSE_DOWN and MOUSE_UP events to click and drag.

  • Keyboard input comes in two event types: KEY_DOWN and KEY_UP.

  • KeyboardEvent objects carry information about the key that was pressed (keyCode) and the character that the key is associated with (charCode), as well as information about modifier keys held down.

  • Character codes are in UTF-8 and can be converted back to their characters with String.fromCharCode().

  • Keyboard input occurs before IMEs convert the input. On some platforms you can control the IME's operation in ActionScript.

  • Only one object has focus at a given time. The Stage instance keeps a reference to that object in its focus property, which can be written to reset focus.

  • Changes in focus dispatch FocusEvent events. You can prevent focus from changing by canceling some of these objects.

  • Pressing Tab on the keyboard cycles through tab-enabled InteractiveObjects in the automatic tab order, sorted by their position on-screen.

  • You can override automatic tab order by setting tabIndex properties on InteractiveObjects.

  • When the keyboard is used to set focus, a focus rectangle appears around certain display objects unless you set focusRect to false. Alternatively, you can control focus rectangles globally with the Stage instance's stageFocusRect property.

  • Use tab ordering, focus indication, good labels, and if necessary AcessibilityProperties (covered in Chapter 41) to help screen readers access your content.

  • Context menus may be customized up to a point by hiding some built-in menu items and adding your own custom ones.

  • Assign a ContextMenu instance to the contextMenu property of the root display object, not the stage, to set the default context menu.

  • To respond to a user activating your ContextMenuItems, listen for the ContextMenuEvent event.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial