13 Replies Latest reply on Jun 30, 2010 3:01 AM by BhaskerChari

    Null reference when passing combobox as argument

    Legion6789145217858656546

      I've got a function that takes a combobox as a parameter and then populates it.  This works fine on 3 of my comboboxes, but not on any of the others.  For all the others it says that they are null.

       

      Function code is here:

      protected function PopulateDateDropdowns():void
                  {
                      PopulateMonths(cmbTDCTSinceMM);
                      PopulateDays(cmbTDCTSinceDD);
                      PopulateYears(cmbTDCTSinceYYYY);
                     
                      PopulateMonths(cmbEmpStartDateMM);
                      PopulateDays(cmbEmpStartDateDD);
                      PopulateYears(cmbEmpStartDateYYYY);

       

                      PopulateMonths(cmbJEmpStartDateMM);
                      PopulateDays(cmbJEmpStartDateDD);
                      PopulateYears(cmbJEmpStartDateYYYY);
                  }
                 
                  private function PopulateDays(cb:spark.components.ComboBox):void
                  {
                      var i:int;
                      cb.dataProvider = new ArrayList();
                      for(i=1; i<32; i++)
                      {
                          cb.dataProvider.addItem(i);
                      }
                  }
                 
                  private function PopulateMonths(cb:spark.components.ComboBox):void
                  {
                      cb.dataProvider = new ArrayList();
                      cb.dataProvider.addItem("Jan");
                      cb.dataProvider.addItem("Feb");
                      cb.dataProvider.addItem("Mar");
                      cb.dataProvider.addItem("Apr");
                      cb.dataProvider.addItem("May");
                      cb.dataProvider.addItem("Jun");
                      cb.dataProvider.addItem("Jul");
                      cb.dataProvider.addItem("Aug");
                      cb.dataProvider.addItem("Sep");
                      cb.dataProvider.addItem("Oct");
                      cb.dataProvider.addItem("Nov");
                      cb.dataProvider.addItem("Dec");
                  }
                 
                  private function PopulateYears(cb:spark.components.ComboBox):void
                  {
                      var i:int;
                      var maxYear:int = new Date().getFullYear() - 18;
                      cb.dataProvider = new ArrayList();
                     
                      for(i=1900; i<maxYear; i++)
                      {
                          cb.dataProvider.addItem(i);
                      }
                  }

       

       

      Declaration of the comboboxes that fail is here:

       

                      <mx:FormItem label="Employment Start Date: " direction="horizontal">
                          <s:ComboBox id="cmbEmpStartDateMM"  width="60"/>
                          <s:ComboBox id="cmbEmpStartDateDD"  width="60"/>
                          <s:ComboBox id="cmbEmpStartDateYYYY" width="100" />
                      </mx:FormItem>

       

      The only difference between these and the ones that work, is that these are declared inside a separate form and canvas.  But I thought that all the script was global to the page elements.