6 Replies Latest reply on Jul 20, 2008 7:11 PM by BlahBoor

    Setting dataProvider programmatically causes null reference

    smokeranch
      I am trying to bind a combo box to a list of countries via an HTTPService that returns xml. If I set the dataProvider and labelField properties declaratively in the mxml then it works great. However, if I try to set it programmatically in the method that gets called after the HTTPService call returns, then I get "TypeError: Error #1009: Cannot access a property or method of a null object reference.".

      Here is the dataServiceResult method:

      [Bindable]
      private var _lookupData:XML;

      public function dataServiceResult(event:ResultEvent):void
      {
      _lookupData = event.result as XML;

      cboCountry.dataProvider = _lookupData.countries.country;
      cboCountry.labelField = "@name";
      }

      This causes the error shown above. However, if I comment out the last two lines of the method and alter the combo box declaration to look like the following, then it works fine:

      <mx:ComboBox id="cboCountry" styleName="RequiredFieldLabel"
      dataProvider="{_lookupData.countries.country}" labelField="@name"
      change="countrySelected()">
      </mx:ComboBox>

      Any ideas? Declarative binding will work in this specific situation but I have several other instances where I will need to programmatically bind to xml, so I need to get this scenario working. Thanks in advance for any help!

      Aaron