4 Replies Latest reply on Oct 21, 2010 6:05 AM by JoGlez

    How to get button ID??

    JoGlez Level 1

      Hi All, ok so I have a ToggleButtonBar and the data provider is an object array. when i click on a button I want to obtain it's id. question is how??

      necessary code is below, thanks

       

      <fx:Array id="Toggle">
                  <fx:Object icon="{barIcon}" id="BarChart"/>           
                  <fx:Object icon="{columnIcon}" id="ColumnChart"/>
                  <fx:Object icon="{lineIcon}" id="LineChart"/>
                  <fx:Object icon="{pieIcon}" id="PieChart"/>
              </fx:Array>

       

      <mx:ToggleButtonBar " itemClick="ChartToggle(event);" " dataProvider="{Toggle}"/>

       

          public function ChartToggle(event:ItemClickEvent):void
                  {
                      var chartType:string = event.?????<--what goes here... thanks guys!!!
               
                  }

        • 1. Re: How to get button ID??
          Flex harUI Adobe Employee

          Try event.label or event.item.id

          • 2. Re: How to get button ID??
            JoGlez Level 1

            event.label would work if I had a label, but I dont. and event.item.id does not work

            at all... Is there a way to assign a label to each button but make the label invisible; only display icon?

            • 3. Re: How to get button ID??
              BhaskerChari Level 4

              Hi JoGlez,

               

              Make your id attribute of the object with upper case instead of lowercase as you are using(either you can use Id or ID) then you can see the Id or ID property in the item property in the click event. Since id is treated here as a predefined property you cannot see it in the item property...

               

              So change your Array to as shown below:

               

              See I have changed the lowercase i to uppercase I.

               

              <fx:Array id="Toggle">
                   <fx:Object icon="{barIcon}" Id="BarChart"/>           
                   <fx:Object icon="{columnIcon}" Id="ColumnChart"/>
                   <fx:Object icon="{lineIcon}" Id="LineChart"/>
                   <fx:Object icon="{pieIcon}" Id="PieChart"/>
              </fx:Array>

               

              and your function should look like...

               

              public function ChartToggle(event:ItemClickEvent):void
                          {
                              var chartType:string = event.item.Id;
                       
                          }

               

               

              Thanks,

              Bhasker

              • 4. Re: How to get button ID??
                JoGlez Level 1

                Resolved Thanks A lot!!! saved about 15 lines of code there!!!