Actionscript 3 带按钮的ItemRenderer:单击按钮时选择的项目

Actionscript 3 带按钮的ItemRenderer:单击按钮时选择的项目,actionscript-3,flash,apache-flex,actionscript,itemrenderer,Actionscript 3,Flash,Apache Flex,Actionscript,Itemrenderer,我需要在列表的每一项中添加一个按钮。以下是我的ItemRenderer的代码: <?xml version="1.0" encoding="utf-8"?> <!-- Item Renderer to render product preview images as thumbnails --> <s:ItemRenderer width="200" clipAndEnableScrolling="false"

我需要在列表的每一项中添加一个按钮。以下是我的ItemRenderer的代码:

<?xml version="1.0" encoding="utf-8"?>
<!--
Item Renderer to render product preview images as thumbnails
-->
<s:ItemRenderer 
            width="200"
            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="com.pms.approvaltool.model.*"
            xmlns:components="com.pms.approvaltool.components.*"
            xmlns:spinner="de.profundus.editor.components.spinner.*">
<fx:Script>
    <![CDATA[


        protected function button1_clickHandler(event:MouseEvent):void
        {
            // TODO Auto-generated method stub

        }

    ]]>
</fx:Script>
<s:VGroup 
          width="100%"
          paddingTop="10"
          paddingBottom="10"
          paddingLeft="10"
          paddingRight="10"
          verticalAlign="middle"
          gap="3">

    <s:Label width="100%"
             text="{(data as Page).label}"/>
    <!-- preview item thumbnail -->
    <mx:Image 
              maxWidth="200" maxHeight="150"
              source="{(data as Page).previewUrl}"
              scaleContent="true"
              maintainAspectRatio="true"/>
        <s:Button click="button1_clickHandler(event)"/>
</s:VGroup>

</s:ItemRenderer>


问题是,当我点击按钮时,相关项目被选中。如何避免这种情况?

尝试停止mouseDown事件向datagrid的传播,如果它像

<s:Button mouseDown="event.stopPropagation()" />

尝试停止mouseDown事件向datagrid的传播,如果它会像

<s:Button mouseDown="event.stopPropagation()" />

您可以从按钮1\u clickHandler访问列表,并将列表的selectionIndex设置为-1。如果itemRenderer是内联的,您可以尝试parentDocument访问父列表。

您可以从按钮1\u clickHandler访问列表,并将列表的selectionIndex设置为-1。如果itemRenderer是内联的,您可以尝试parentDocument访问父列表。

根据,您可以使用
事件。stopImmediatePropagation

<s:Button mouseDown="event.stopImmediatePropagation()" />

以下SO帖子可能也会有所帮助:

根据,您可以使用
事件。停止即时复制

<s:Button mouseDown="event.stopImmediatePropagation()" />

以下SO帖子可能也会有所帮助:

您是否尝试过类似event.currentTarget.selected=false的方法;在事件处理程序中?如果选择了它,会出现什么问题?如果是因为背景原因,您可以在itemRenderer AutoDruckGround=False中尝试。当列表项也被选中时,我有一些操作要做。我不希望在按下按钮时执行这些操作。您是否尝试过类似event.currentTarget.selected=false的操作;在事件处理程序中?如果选择了它,会出现什么问题?如果是因为背景原因,您可以在itemRenderer AutoDruckGround=False中尝试。当列表项也被选中时,我有一些操作要做。不幸的是,我不知道我的和你的有什么不同,但我只是尝试创建你的itemrenderer,停止mouseDown事件的传播是有效的…看起来我错了。至少现在我有了stopImmediatePropagation()调用的功能。不幸的是,我不知道我的和你的有什么不同,但我刚刚尝试创建了你的itemrenderer,停止mouseDown事件的传播是有效的……看起来我错了。至少现在我有了stopImmediatePropagation()调用工作。