2 Replies Latest reply on Jan 13, 2009 3:47 PM by j.ochoa

    Using data binding on invididual buttons in a ToggleButtonBar

    j.ochoa Level 1
      Can someone tell me if it's possible to use data binding on the individual buttons in a ToggleButtonBar and, if so, how?

      I want to be able to use data binding for the "enabled" property of each individual button in the ToggleButtonBar, but that's not possible using MXML because the ToggleButtonBar takes a data provider to render the labels of each button and, obviously, I can't set the "enabled" property on the dataprovider values because they're not Button objects. For example, I'm not allowed to do something like this:

      <mx:ToggleButtonBar id="tbb"
      toggleOnClick="true"
      itemClick="clickHandler( event )"
      creationComplete="tbb.selectedIndex=-1">

      <mx:Button label="A" enabled="{...}" />
      <mx:Button label="B" enabled="{...}" />
      <mx:Button label="C" enabled="{...}" />

      </mx:ToggleButtonBar>
        • 1. Re: Using data binding on invididual buttons in a ToggleButtonBar
          rtalton Level 4
          Ah! The ToggleButtonBar. Binding. MXML. Mysterious. Un-obvious. But yes, it CAN be done...
          First, you'll need to get at the toggle buttons. Did you know they are actually ButtonBarButtons? Once you get an instance of each one, you can do the binding in MXML.

          Each LINK button below the ViewStack is bound to a ToggleBarButton.
          When you click on a related Button below it, the LINK button above it will have its enabled property toggled. Then a binding will fire, setting the related ToggleBarButton's enabled property.

          This example requires you to know ahead of time how many Toggle Buttons and Buttons you have, so it will not scale well. Each time you add a button, you'd have to hard code it into the "getButtons" function, which sets up the ButtonBarButton instances. But if you have a known quantity of buttons, no problem.

          • 2. Re: Using data binding on invididual buttons in a ToggleButtonBar
            j.ochoa Level 1
            Yes, perfect! This is exactly what I need.

            I did know the buttons were of type ButtonBarButton, but I was treating them as type Button as Flex 3 doesn't seem to recognize the mx.controls.buttonBarClasses package (even though importing it does work).

            In any case, I really appreciate your help.

            Thanks,
            -Jose