开发者

Dynamic populate ComboBox (Flex)

I want to populate a ComboBox after a clicked a button.

This is my code:

    var dpNames:ArrayCollection = new ArrayCollection();
    for each(var ca:Categorie in arrCategories)
    {
   开发者_JAVA技巧       dpNames.addItem ({label: ca.name, data: ca.value});
    }       

    cbWijzigCategorie.dataProvider = dpNames;

But when he executes the last line, I alwas get the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

I have no idea why.

Thanks a lot, Vincent


    private function categorieItemClick(evt:ItemClickEvent):void
    {

            var dpNames:ArrayCollection = new ArrayCollection();
            for each( var ca:Categorie in arrCategories)
            {
                dpNames.addItem ({label: ca.Name, data: ca.Name});
            }                   
            cbWijzigCategorie.dataProvider = dpNames;


    }



<mx:ButtonBar 
        x="10" y="36" 
        id="tbtnbarCategorie" 
        dataProvider="vsCategorie" 
        itemClick="categorieItemClick(event)">
</mx:ButtonBar>

    <mx:ViewStack 
        x="10" y="64" 
        id="vsCategorie" 
        width="601" height="343">

           <mx:Canvas label="Wijzig categorie" 
        id="cnvsChangeCategorie" 
        width="100%" height="100%">
        <mx:Label 
        x="10" y="10" 
        text="Kies categorie"/>
             <mx:ComboBox 
        x="101" y="8" 
        id="cbWijzigCategorie"></mx:ComboBox>
           </mx:Canvas>

    </mx:ViewStack>


Is your combobox instanciated? Looking at the error message, the problem would come from "cbWijzigCategorie.datprovider". It cannot access the dataprovider property cause cbWijzigCategorie is null.

Where are you assigning the dataprovider to the combobox? Inside the or outside the component?

Regards.


Make sure arrCategories isn't empty and is properly initialized.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜