4 Replies Latest reply on Oct 22, 2008 11:12 AM by m_hartnett

    Set color of selected button in ButtonBar ?

    EvolvedDSM Level 2
      I noticed that there's no specific style property for setting any styles to the selected button on a button bar. For instance, regardless of which button you choose on a button bar, they do not visually indicate which button was selected.

      Is there any work-around coding I could do to change the background color of a button in a button bar? Using firstButtonStyleName and lastButtonStyleName only style the first and last buttons of your button bar. It's too bad it doesn't work in a way that it styles the first button selected by default when the app loads and then styles the last button selected.

      If anyone has created a work-around for this, let me know!
        • 1. Re: Set color of selected button in ButtonBar ?
          Level 7
          Try ToggleButtonBar

          "EvolvedDSM" <webforumsuser@macromedia.com> wrote in message
          news:g7s80l$gcg$1@forums.macromedia.com...
          >I noticed that there's no specific style property for setting any styles to
          >the
          > selected button on a button bar. For instance, regardless of which button
          > you
          > choose on a button bar, they do not visually indicate which button was
          > selected.
          >
          > Is there any work-around coding I could do to change the background color
          > of a
          > button in a button bar? Using firstButtonStyleName and
          > lastButtonStyleName
          > only style the first and last buttons of your button bar. It's too bad it
          > doesn't work in a way that it styles the first button selected by default
          > when
          > the app loads and then styles the last button selected.
          >
          > If anyone has created a work-around for this, let me know!
          >


          • 2. Re: Set color of selected button in ButtonBar ?
            BrianJPM
            I also have the same problem in that I want to change the background colour of the selected button. The toggleButtonBar control appears to have a selectedButtonTextStyleName but not a selectedButtonStyleName. The former does not appear to support the fillColors property.

            Thanks
            Brian
            • 4. Re: Set color of selected button in ButtonBar ?
              m_hartnett Level 3
              Here is a sample of a much more complicated custom button object that we use.

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
              layout="absolute"
              creationComplete="init()">
              <mx:Script>
              <![CDATA[

              private var lastBtnId : String;
              private var lastBtnArray : Array;
              private function btnClick(e:Event) : void {

              //get out because the user clicked the same button
              if(lastBtnId == e.currentTarget.id) return;

              //reset the previous button before we save the current clicked button
              if(lastBtnId != null && lastBtnId != e.currentTarget.id) {
              var btn : Button = this.getChildByName(lastBtnId) as Button;
              btn.setStyle("fillColors",lastBtnArray);
              }


              //Save the current clicked button styles
              lastBtnId = e.currentTarget.id;
              lastBtnArray = e.currentTarget.getStyle("fillColors");
              //more styles here if you want

              //change the style of the clicked button
              e.currentTarget.setStyle("fillColors", ["#006666", "#33ff99", "#000066", "#00ff33"])


              }
              ]]>
              </mx:Script>


              <mx:Button id="btn1" x="44" y="60" label="Button" click="btnClick(event)"/>
              <mx:Button id="btn2" x="124" y="60" label="Button" click="btnClick(event)"/>


              </mx:Application>