Flex:stopPropagation事件Keyboard.ENTER的颜色选择器

时间:2010-02-22 15:20:41

标签: flex3 keyboard-events propagation

我在KeyboardEvent上有一个带有侦听器的WindowedApplication(在ENTER键上),但是当用户选择使用颜色选择器并键入十六进制代码然后按Enter时,事件也被提供给我的WindowedApplication。 我必须停止传播。 任何提示或片段? 谢谢 P上。

2 个答案:

答案 0 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx" 
        keyDown="appHandler(event)">
 <fx:Script>
  <![CDATA[
   import mx.controls.Alert;
   import mx.events.FlexEvent;

   private function appHandler(event:KeyboardEvent):void
   {
    trace('A key has been pressed inside the app');
   }

   private function cpHandler(event:KeyboardEvent):void
   {
    trace('A key has been pressed inside the color picker');
    event.stopPropagation();
   }

  ]]>
 </fx:Script>

 <mx:ColorPicker x="159" y="137" id="cp" keyDown="cpHandler(event)"/>
 <s:TextInput x="233" y="137"/>

</s:WindowedApplication>

答案 1 :(得分:0)

这是TitleWindow代码的一部分,其中cp是ColorPicker。

...     

public function init():void {cp.addEventListener(ColorPickerEvent.ENTER,handler); }

public function handler(e:ColorPickerEvent):void { e.stopImmediatePropagation(); }

public function changeColor(e:ColorPickerEvent):void { Application.application.couleur = cp.selectedColor; PopUpManager.removePopUp(本); } ...

这是来自我的主要mxml:

... employeeList.addEventListener(KeyboardEvent.KEY_UP,enterListener); ...

私有函数enterListener(e:KeyboardEvent):void {
if(e.keyCode == Keyboard.ENTER){
    if(employeeList.selectedItem){
        showDetail(employeeList.selectedItem as Employee);
    }
}
}