Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex 3.5.0; Update ComboBox display list upon dataprovider change

I have two related ComboBoxes ( continents, and countries ). When the continents ComboBox changes I request a XML from a certain URL. When I receive that XML i change the DataProvider for the countries ComboBox, like this:

public function displayCountryArray( items:XMLList ):void
        {
            this.resellersCountryLoader.alpha = 0;
            this.resellersCountry.dataProvider = items;
            this.resellersCountry.dispatchEvent( new ListEvent( ListEvent.CHANGE ) );
        }

I dispatch the ListEvent.CHANGE because I use it to change another ComboBox so please ignore that (and the 1st line ).

So, my problem is this: I select "ASIA" from the first continents, then the combobox DATA get's updated ( I can see that because the first ITEM is an item with the label '23 countries' ). I click the combo then I can see the countries.

NOW, I select "Africa", the first item is displayed, with the ComboBox being closed, then when I click it, the countries are still the ones from Asia. Anyway, if I click an Item in the list, then the list updates correctly, and also, it has the correct info ( as I said it affects other ComboBoxes ). SO the only problem is that the display list does not get updated.

In this function I tried these approaches

  • Converting XMLList to XMLCollection and even ArrayCollection

  • Adding this.resellersCountry.invalidateDisplayList();

  • Triggering events like DATA_CHANGE and UPDATE_COMPLETE I know they don't make much sense, but I got a little desperate.

Please note that when I used 3.0.0 SDK this did not happen.

Sorry if I'm stupid, but the flex events are killing me.

like image 246
Gabriel Poama-Neagra Avatar asked Mar 30 '10 14:03

Gabriel Poama-Neagra


3 Answers

Setting the dataprovider of the comboBox' dropdown seems to fix this problem.

this.resellersCountry.dataProvider = items;
this.resellersCountry.dropdown.dataProvider = items;
like image 176
Christophe Herreman Avatar answered Nov 09 '22 18:11

Christophe Herreman


this.resellersCountry.dropdown.dataProvider = items;

works (Flex SDK 3.5)

Hope this bug fixed in 4.0

like image 42
Rodion Bykov Avatar answered Nov 09 '22 18:11

Rodion Bykov


In addition to Christophe´s answer:

When you are using data binding in your ComboBox you need to use the BindingUtils to set the dropdown´s dataprovider:

MXML:

<mx:ComboBox id="cb_fontFamily"
        width="100%"
        dataProvider="{ model.fontFamilies }" />

Script:

private function init():void
{
    BindingUtils.bindSetter(updateFontFamilies, model, "fontFamilies");
}

private function updateFontFamilies(fontFamilies:ArrayCollection):void
{
    if (cb_fontFamily != null) cb_fontFamily.dropdown.dataProvider = fontFamilies;
}

Thanks to Christophe for pointing in the right direction.

like image 35
Konsumierer Avatar answered Nov 09 '22 16:11

Konsumierer