
Key.removeListener() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
567
The onKeyDown( ) and onKeyUp( ) events are triggered precisely once for each keypress
and key release. When using onKeyUp( ) and onKeyDown( ), you need not concern yourself
with whether the key is still being pressed at any given instant. Using these events allows
you to detect keypresses accurately even if the user releases the key between frames, and it
also prevents you from checking the same key twice if it was pressed only once. In any case,
you will ordinarily use the Key.getCode( ) and Key.getAscii( ) methods to check for the last
key pressed within an onKeyDown( ) or onKeyUp( ) listener.
The onKeyUp( ) event executes immediately when a key is released, independent of the
code on a movie’s timeline(s). However, visual changes to the movie made by the listener
are not rendered until the next frame refresh, which is determined by the frame rate of the
movie. Unfortunately, in Flash 6, updateAfterEvent( ) cannot be used to force a screen
refresh from onKeyUp( ); updateAfterEvent( ) has an effect only when invoked either from a
movie clip mouse or key event, or a setInterval( ) callback.
Usage
To emulate onKeyUp( ) in Flash 5, use the MovieClip class’s on(keyUp) clip event attached
to a movie clip at authoring time. For ...