2010-11-25 66 views
0

我有一個自定義項目渲染器,即時通訊使用在列表中。項目渲染器中有一個CheckBox和一個ColorPicker。我爲這兩個項目創建了自己的自定義事件類,並且它們不冒泡他們的事件。Flex4 List ItemRenderer子項和事件

您還可以單擊列表中的項目,我有3個監聽器附加到列表中,我不希望列表項處理程序在列表中的子項被點擊時觸發,我該怎麼做?下面

提取物:

 protected function updateList():void 
    { 
    var proxy:ApplicationDataProxy = ApplicationDataProxy(facade.retrieveProxy(ApplicationDataProxy.NAME)); 
    list.addEventListener(CustomColorEvent.UPDATED_COLOR, colorClickHandler); 
    list.addEventListener(CustomMenuEvent.CHECK_CLICKED, checkClickHandler); 
    list.addEventListener(MouseEvent.CLICK, clickHandler); 
    list.itemRenderer = new ClassFactory(FlightItemRenderer); 
    list.dataProvider = proxy.flightsList; 
    } 

    protected function colorClickHandler(event:CustomColorEvent):void 
    { 
    sendNotification(ApplicationFacade.UPDATE_COLOR, {id:event.data, color:event.color}); 
    } 

    protected function checkClickHandler(event:CustomMenuEvent):void 
    { 
    sendNotification(ApplicationFacade.SHOW_FLIGHT, {id:event.data, visible:event.visible}); 
    } 

    protected function clickHandler(event:Event):void 
    { 
    // also gets fired from colours and checkbox, BUT I DON'T WANT IT TO!!! 
    } 

回答

1

添加點擊監聽到你的項目渲染器,並檢查event.target財產,看看它是否是被點擊,如果是,你可以調用event.stopImmediatePropagation()的複選框。這是一個非常簡單的例子,沒有其他的MouseEvent.CLICK監聽器會被觸發。

<s:List> 
    <s:itemRenderer> 
     <fx:Component> 
      <s:CheckBox click="checkbox1_clickHandler(event)" /> 
       <fx:Script> 
        <![CDATA[ 
         protected function checkbox1_clickHandler(event:MouseEvent):void 
         { 
          //You could also add this click listener 
          //to the renderer itself if you need to do 
          //something when the checkbox is clicked 
          event.stopImmediatePropagation(); 
         } 
        ]]> 
       </fx:Script> 
     </fx:Component> 
    </s:itemRenderer> 
</s:List> 
+0

感謝您的回覆,我正在尋找的東西,從來沒有使用過,但知道它。 – Neil 2010-11-26 11:43:58

相關問題