2010-05-28 61 views
0

我有一個帶有itemrenderer的列表。當我在itemrenderer中放置一個按鈕時,我無法與它進行交互。如果我滾動按鈕,列表項翻轉被觸發,但不是按鈕的翻轉。我也無法點擊按鈕。您可以在下面看到我在itemrenderer中設置了一個單擊事件,並且在運行應用程序時不會單擊它。我必須重寫滾動並單擊itemrender的方法嗎?爲什麼把一個按鈕放在一個itemrenderer中是一件很痛苦的事情?我肯定錯過了什麼。謝謝。Flex無法與itemrenderer中的按鈕進行交互

<!---From main.mxml--> 
<s:List width="100%" borderVisible="false" 
    itemRenderer="itemRenderers.data_resultLayersRenderer" 
    dataProvider="{resultsLayers}"/> 

<!---From itemRenderes--> 
<s:ItemRenderer 
xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/mx" 
xmlns:skins="skins.*" autoDrawBackground="true"> 

<fx:Script> 
    <![CDATA[ 
     import mx.controls.Alert; 
     [Bindable] 
     [Embed('images/add2.png')] 
     public var addIcon:Class; 

     [Bindable] 
     [Embed('images/delete2.png')] 
     public var deleteIcon:Class; 


     protected function iconbutton1_clickHandler(event:MouseEvent):void 
     { 
      Alert.show('test'); 
     } 

    ]]> 
</fx:Script> 

<s:states> 
    <s:State name="normal"/> 
    <s:State name="hovered"/> 
</s:states> 

<s:layout> 
    <s:VerticalLayout/> 
</s:layout> 

<s:transitions> 
    <mx:Transition toState="hovered"> 
     <s:Animate target="{item}" duration="200"> 
      <s:SimpleMotionPath property="borderWeight" /> 
     </s:Animate> 
    </mx:Transition> 
    <mx:Transition fromState="hovered"> 
     <s:AnimateColor target="{item}" duration="200"/> 
    </mx:Transition> 
</s:transitions> 

<mx:HBox id="item" verticalAlign="middle" width="100%" height="100%" 
     useHandCursor="true" buttonMode="true" mouseChildren='false' 
     paddingTop="5" paddingBottom="5"> 
     <s:Label id="subMenuItemName" text="{data.name}" 
       color="#000000" color.hovered="#ff9a15" 
       fontSize="12" fontWeight.hovered="bold" 
       fontFamily="Georgia"/> 
     <s:Label text="{'(' + data.result + ')'}" 
      id="subMenuItemDescription" 
      color="#333333" color.hovered="#ff9a15" 
      fontSize="10"/> 
    <skins:IconButton 
       label="Remove" 
       icon="{deleteIcon}" 
       skinClass="skins.iconButtonSkin" 
       color="#ffffff" 
       /> 
    <skins:IconButton 
     label="Add" 
     icon="{addIcon}" 
     skinClass="skins.iconButtonSkin" 
     color="#ffffff" 
     click="iconbutton1_clickHandler(event)" 
     /> 
</mx:HBox> 

回答

2

看起來像你有mouseChildren設置爲您的項目渲染器中的fase。通過將此屬性設置爲false,可以停止將任何鼠標事件傳播到容器的子項。嘗試將其設置爲true,看看會發生什麼。

+0

就是這樣。謝謝你,先生! – mrjrdnthms 2010-05-28 22:44:34