Flex无法与itemrenderer中的按钮进行交互

时间:2010-05-28 18:55:58

标签: flex events button itemrenderer

我有一个包含itemrenderer的列表。当我在itemrenderer中放一个按钮时,我无法与它交互。如果我翻转按钮,则会触发列表项翻转,但不会触发按钮的翻转。我也无法点击按钮。你可以在下面看到我在itemrenderer中设置了一个click事件,当我运行app时它没有被点击。我必须覆盖rollover并单击itemrender的方法吗?为什么在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>

1 个答案:

答案 0 :(得分:2)

您的项呈示器中似乎有mouseChildren设置为fase。通过将此属性设置为false,可以阻止任何鼠标事件传播到容器的子项。尝试将其设置为true,看看会发生什么。