Link to home
Start Free TrialLog in
Avatar of FlexingCF
FlexingCF

asked on

Dynamically selecting a combo box item (from db)

I am trying to dynamically select a combobox item from a value stored in a database. The initial combobox values come from an .as file, which is working fine. When I put in the code to trigger the selected item, I get this strange cannot reference a null object or method error.

I will post the .as code for the combobox values, as well as the flex code.

P.S. I am recycling existing, working code, and am not sure why this isn't working...

.as [combobox values]
package com.Evolve.UI.ComboValues
{
	
	import mx.collections.*;
	
	public class DealCB
	{
		public function DealCB()
		{
		}
		
		
		public var combo_RentalTerms:Array = 
	    [{label:"Annually", data:"Annually"},
	    {label:"Quarterly", data:"Quarterly"},
	    {label:"Monthly", data:"Monthly"},
	    {label:"Weekly", data:"Weekly"},
	    {label:"Daily", data:"Daily"}];
	    
 
	}
}
 
.mxml file
OBJECT
<mx:ComboBox id="cb_RentalTerm_edit" dataProvider="{acRentalTerms}" labelField="label"/>
 
 
[Bindable] private var acRentalItem:ArrayCollection;
[Bindable] private var acRentalTerms:ArrayCollection;
 
Init Func: {
var _dcb:DealCB = new DealCB();
acRentalTerms = new ArrayCollection(_dcb.combo_RentalTerms);
}
 
private function getDealRentalItem_result(event:ResultEvent):void {
acRentalItem = event.result as ArrayCollection;
			
for (var i:int = 0; i < cb_RentalTerm_edit.dataProvider.length; i++) {
if (acRentalItem.getItemAt(0).RentalTerm == cb_RentalTerm_edit.dataProvider[i].label) {
cb_RentalTerm_edit.selectedIndex = i;
break; }
}
this.do_Nav("Edit");
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mplord
mplord
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FlexingCF
FlexingCF

ASKER

I will look into that, but I believe I do.

I'm populating an edit form from a single record returned from a cfc, and all other fields are populating. I've made sure that each record contains a value, and the field names are correct. Is it possible that I need to strip for empty spaces (although there should be no extra spaces).
mplord, yes, there is always an event.result with one record.