2010-11-25 4 views
0

List에서 사용하는 사용자 정의 항목 렌더러가 있습니다. 항목 렌더러에는 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.stopImmediatePropagation()를 호출 할 경우, 클릭 한 체크 박스했다 있는지 확인하기 위해 event.target 속성을 확인합니다. 아주 간단한 예제입니다. 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