1 Reply Latest reply on Dec 30, 2010 9:56 PM by flex2008

    Buttons in List

    dpark1113

      Hi,

       

      I have spark buttons in List.  I would like to trigger different task when user clicks the button, but not to trigger the list item.  Is there an "isClick" attribute on spark button?

       

      Thanks!

        • 1. Re: Buttons in List
          flex2008 Level 3

          1) Use a button item renderer for list
          2) Add click event handler for button
          3) In click event handler,use something like label of the button to uniquely identify the button which is clicked and based on that write the logic you want to implement.

           

          Here is a simple example for you:

           

          <?xml version="1.0" encoding="utf-8"?>
          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                         xmlns:s="library://ns.adobe.com/flex/spark" 
                         xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
              <s:layout>
                  <s:VerticalLayout/>
              </s:layout>
              <fx:Declarations>
                  <!-- Place non-visual elements (e.g., services, value objects) here -->
              </fx:Declarations>
              <s:List width="150" height="250" itemRenderer="ButtonRenderer">
                  <s:layout>
                      <s:VerticalLayout/>
                  </s:layout>
                  <s:dataProvider>
                      <s:ArrayList>
                          <fx:String>Btn1</fx:String>
                          <fx:String>Btn2</fx:String>
                          <fx:String>Btn3</fx:String>
                          <fx:String>Btn4</fx:String>
                          <fx:String>Btn5</fx:String>
                          <fx:String>Btn6</fx:String>
                      </s:ArrayList>
                  </s:dataProvider>
              </s:List>
          </s:Application>

           

          Here is the ButtonRenderer class:

           

          <?xml version="1.0" encoding="utf-8"?>
          <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" 
                          autoDrawBackground="false">
          
              <fx:Script>
                  <![CDATA[
                      import mx.controls.Alert;
                      protected function button1_clickHandler(event:MouseEvent):void
                      {
                          if(event.currentTarget.label == 'Btn4')
                          {
                              Alert.show('You have clicked Btn4');
                          }
                          else
                          {
                              Alert.show('You have clicked some other btn');
                          }
                              
                      }
                  ]]>
              </fx:Script>
          
              
              <s:Button label="{data}" click="button1_clickHandler(event)"/>
              
          </s:ItemRenderer>