
Keyboard events 117
Maintaining scope
Previously, you used the mx.utils.Delegate class to provide access to the document scope
within an event handler. You would pass the Delegate object into a call to the
addEventListener() method so that the listener would execute in that scope. This is no
longer necessary. The event listener’s scope is now the class in which it is declared as a
function, which is in most cases the scope you should expect; for example:
Flex 1.x:
addEventListener("click", mx.utils.Delegate.create(this, myListener));
Flex 2:
addEventListener(MouseEvent.CLICK, myListener);
Using setCapture()
The setCapture() method has been removed. This method was added in earlier Beta releases
of Flex 2 and was used to block events going to other (nested or non-nested) components
during drag-and-drop operations and a few other interactions. However, in the nested
situation, if one component called the
setCapture() method, its parents and children could
not.
If you require this functionality, you should use the capture phase of the event model by
calling the
stage.addEventListener("mouseXXX", mouseXXXHandler, true) method,
where
mouseXXX is the mouse event you want to block. You can then emulate the
setCapture() method by calling the event.stopPropagation() method; however, Adobe
does not recommend doing this because most components should ignore the event.
The
removeCapture() method has also been removed.
Keyboard events
The code and ascii properties of the KeyboardEvent (formerly Event) object are now
keyCode and charCode.
In drag-and-drop examples in Flex 1.x, you could use
Key.isDown() to detect a key that was
pressed during the operation. In Flex 2, you use the
shiftKey, ctrlKey, and altKey
properties on the KeyboardEvent object to detect keys that are pressed during the operation.
Komentáře k této Příručce