4 Replies Latest reply on Aug 25, 2010 1:41 AM by BhaskerChari

    Cannot Identify which buton is cliked on ToggleButonBar

    kiran7881 Level 1

      Hi ,

       

      I am trying to  use ToggleButtonBar control within my  Form .
      I am some problem , as i couldn;t able to identify which button has been clkicked on.

       

      This is my sample code , please let me know how can i solve this:\

       


          <mx:ToggleButtonBar
              borderStyle="solid"
              horizontalGap="5"
              itemClick="clickHandler(event);"
              toggleOnClick="true"
              >
             
              <mx:dataProvider>
                  <mx:String id="add">ADD</mx:String>
                  <mx:String id="update">UPDATE</mx:String>
                  <mx:String id="deleted">UPDATE</mx:String>
              </mx:dataProvider>

       

          </mx:ToggleButtonBar>

       

       

       

      public function clickHandler(event:ItemClickEvent):void
      {
      Alert(event.target.id) // This is comimg as an empty alert
      }

       

      Please tell me how can i solve this .

       

      Thanks .

        • 1. Re: Cannot Identify which buton is cliked on ToggleButonBar
          flex4 Level 2

          Hi Kiran

           

           

           

           

                         Just Now i have gone through ur code.. here currentTarget means toggle button bar and id property means it's an object

           

           

                                 so u want to display which item is clicked u need to do some modification

           

           

                                check out this code in ur function..

           

                                   public function clickHandler(event:ItemClickEvent):void
                                        {
                                                  Alert.show(event.item as String) ;
                                        }

           

                         I think this will solve ur problem..

           

                          keep flexing

          1 person found this helpful
          • 2. Re: Cannot Identify which buton is cliked on ToggleButonBar
            BhaskerChari Level 4

            Hi Kiran,

             

            Here is the code which solves ur problem..

             

            <?xml version="1.0" encoding="utf-8"?>

            <mx:Application

             

             

            xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

             

             

            <mx:Script>

            <![CDATA[

             

             

            import mx.controls.Alert;

             

            import mx.events.ItemClickEvent;

             

             

            public function clickHandler(event:ItemClickEvent):void

            {

            Alert.show(

             

            "You have clicked " + event.label + " button") // This is comimg as an empty alert

            }

            ]]>

             

             

            </mx:Script>

             

            <mx:ToggleButtonBar

            borderStyle="

            solid"

            horizontalGap="

            5"

            itemClick="clickHandler(event);"

            toggleOnClick="

            true"

             

            >

             

            <mx:dataProvider>

             

            <mx:String id="add">ADD</mx:String>

             

            <mx:String id="update">UPDATE</mx:String>

             

            <mx:String id="deleted">DELETE</mx:String>

             

            </mx:dataProvider>

             

            </mx:ToggleButtonBar>

            </mx:Application>

             

             

             

            Thanks,

            Bhasker

             

            • 3. Re: Cannot Identify which buton is cliked on ToggleButonBar
              kiran7881 Level 1

              Thank you very much , if you provide me the solution , that will work , but  how can one remember all these things ??

               

              How can one remember event.item as String OR event.label ??

               

              Please let me know if there is any thumb rule for this ??

               

              Thank you very much .

              • 4. Re: Cannot Identify which buton is cliked on ToggleButonBar
                BhaskerChari Level 4

                Hi Kiran,

                 

                Every event will have different properties ... whether you use event.label or event.item depends on the situation and the requirement you need..

                 

                Each property has its own significance...However the code intellisense will help you in choosing the property...If you are not sure what property to use then just put a break point and watch the

                 

                expression or variable in which you want to locate any required property...This way you can always can check for which property to use..

                 

                 

                 

                Thanks,

                Bhasker