单击List组件内的按钮也可以选择项目

时间:2014-04-28 12:15:30

标签: actionscript-3 flex flex4 itemrenderer

我有来自hereList ItemRenderer组件。当我点击此渲染器内的Button时,列表项也会被选中。我不希望它成为。

我也尝试过我自己想要使用的ItemRenderer。这是代码:

<s:ItemRenderer 
            width="130"
            dataChange="dataChangeHandler(event)"
            clipAndEnableScrolling="false"
            xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:mx="library://ns.adobe.com/flex/mx"
            autoDrawBackground="true"
            xmlns:model="....model.*"
            xmlns:components="....components.*"
            creationComplete="{spinner.play()}">
<fx:Script>
    <![CDATA[

        import mx.core.UIComponent;
        import mx.events.FlexEvent;

        //--------------------------------------------------------------------------
        //
        // Variables
        // 
        //--------------------------------------------------------------------------
        /**
         * Status of the preview item: undefined, discarded or approved.
         */
        private var actualPreviewStatus:String = "";

        //--------------------------------------------------------------------------
        //
        // Handlers
        // 
        //--------------------------------------------------------------------------
        protected function dataChangeHandler(event:FlexEvent):void
        {
            //In Callas version we don't need to handle different statuses.
            if (data && actualPreviewStatus != data.status)
            {
                actualPreviewStatus = data.status;
                switch (data.status)
                {
                    case PrintItem.STATUS_UNDEFINED:
                    {
                        //indicator.styleName = "";
                        break;
                    }
                    case PrintItem.STATUS_DISCARDED:
                    {
                        //indicator.styleName = "itemDiscardedStyle";
                        //itemStatus.text = resourceManager.getString("localization", "ThumbnailsArea.ItemDiscarded");
                        AppEventBus.instance.dispatchAppEvent(AppEvent.ANIMATE_PREVIEW_DISCARD, localToGlobal(new Point(indicator.x, indicator.y)));
                        break;
                    }
                    case PrintItem.STATUS_APPROVED:
                    {
                        //indicator.styleName = "itemApprovedStyle";
                        //itemStatus.text = resourceManager.getString("loclization", "ThumbnailsArea.ItemApproved");
                        AppEventBus.instance.dispatchAppEvent(AppEvent.ANIMATE_PREVIEW_APPROVE, localToGlobal(new Point(indicator.x, indicator.y)));
                        break;
                    }
                    default:
                        break;
                }
            }
        }

        protected function image_updateCompleteHandler(event:FlexEvent):void
        {
            if((event.target as Image).width != 0)
                spinnerContainer.visible = false;
        }

        protected function button1_clickHandler(event:MouseEvent):void
        {
            event.stopImmediatePropagation();
        }

    ]]>
</fx:Script>
<s:VGroup 
          width="100%"
          paddingLeft="13"
          verticalAlign="middle"
          gap="3">

    <mx:Text width="100%"
             text="{(data as PrintItem).label}"/>
    <!-- preview item thumbnail -->
    <mx:Image 
              maxWidth="90" maxHeight="60"
              source="{(data as PrintItem).source}"
              scaleContent="true"
              maintainAspectRatio="true"
              updateComplete="image_updateCompleteHandler(event)"/>
    <mx:Text id="itemStatus"
             width="100%"
             styleName="smallText"/>

</s:VGroup>
<s:Group
         id="spinnerContainer"
         width="100%" height="100%">
    <s:Rect width="100%" height="100%">
        <s:fill><s:SolidColor color="0xFFFFFF" /></s:fill>
    </s:Rect>
    <components:Spinner id="spinner"
                        verticalCenter="0" horizontalCenter="0" />
</s:Group>

<s:Button
    label="test"
    click="button1_clickHandler(event)"
    alpha="1.0"/>
<!-- preview item status indicator -->
<s:Button id="indicator"
          y="37"
          visible="false"
          mouseEnabled="false"
          skinClass="com.pms.approvaltool.skins.ImageButtonSkin"/>

这是我如何初始化我的列表(它是自定义的,但只添加了1个属性以防止键盘导航):        

它的工作方式完全相同 - 当我点击一个按钮时,列表项会变为选择。 如何使其正常工作以便Button拦截所有鼠标事件?

0 个答案:

没有答案