Tutorial :flex ButtonBar problem


I want to generate a button sequence on ButtonBar with some disabled buttons:

<mx:Script>          <![CDATA[              import mx.collections.ArrayCollection;                [Bindable]              public var nav:ArrayCollection=new ArrayCollection();                ...                function initApp():void              {                  nav.removeAll();                    for(var i:uint=0;i<navSize;i++)                  {                  nav.addItem({label: i });                  }                    nav.addItem({label: "Last", enabled:false});                }          ]]>      </mx:Script>                    ...  <mx:ButtonBar id="btnBar" dataProvider="{nav}"/>  

but why the last button is still enabled?

UPD: I found solution by adding updateComple event handler:

function upd()              {                  trace("upd()");                  for (var i:int=0; i < btnBar.numChildren; i++)                  {                      if ([condition])                      {                          Button(btnBar.getChildAt(i)).enabled=false;                      }                  }              }  

Anybody have better solution?


The ButtonBar considers items in your dataProvider as generic objects. It will not look into those objects for values other than label. The way that list classes work is there is a labelField, a labelFunction, and a method named itemToLabel. I assume that the ButtonBar uses a similar approach.

The itemToLabel function is called whenever the component needs to find the label from the item in your dataPRovider. It will not look into your dataProvider for other settings and that is why the enabled property in your dataProvider has no effect.

I'm unclear exactly why you want to disable buttons in the ButtonBar. Knowing that would help us give you direction on where to put the code. Using the ButtonBar's updateComplete event will run that code every time the component's visual display is updated, which you probably don't want.

You can run this code on creationComplete, which is a one time event. But, if you need constant updates this would not work.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »