1

I need to add a button to each item of the list. Here is my ItemRenderer's code:

<?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>

The issue is that when I click on the button the related item becomes selected. How can I avoid this?

Brian
  • 3,850
  • 3
  • 21
  • 37
Lingviston
  • 5,479
  • 5
  • 35
  • 67
  • have you tried something like event.currentTarget.selected = false; in the event handler? – The_asMan Jan 21 '14 at 14:30
  • What is the problem if it got selected? If it is because of background you can try in itemRenderer autoDrawBackground=false – Nemi Jan 21 '14 at 15:37
  • I have some actions to be done when list item selected too. And I don't want them to be done if button is pressed. – Lingviston Jan 21 '14 at 22:17

3 Answers3

3

try to stop propagation of mouseDown event to the datagrid, if it will work like...

<s:Button mouseDown="event.stopPropagation()" />
user3190916
  • 737
  • 8
  • 8
  • Unfortunatelly I don't know what is different between mine and yours , but I just tried create your itemrenderer and stopping propagation of mouseDown event is working.... – user3190916 Feb 02 '14 at 12:25
  • Looks like I was wrong. At least now I have it with stopImmediatePropagation() call working. – Lingviston Aug 20 '14 at 21:36
1

According to http://forums.adobe.com/thread/776750, you can use event.stopImmediatePropagation:

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

The following SO post might also help: Prevent selection of a particular item in spark list

Community
  • 1
  • 1
Brian
  • 3,850
  • 3
  • 21
  • 37
0

You could access List from button1_clickHandler and set list's selectionIndex to -1. If itemRenderer is inline you can try parentDocument to access parent List.

Nemi
  • 1,012
  • 10
  • 19