views:

198

answers:

3

Hi,

I was trying to filter a combo box dataprovider based on the values in the text boxes . When the contents of the dataprovider changes Combo box automatically calls change event method . Please find the sample code below.

Filter Utility Function:

private function filterLocations(event:FocusEvent):void {
    locationsList1.filterFunction = filterUtility;  
    locationsList1.refresh();                          
}   

public function filterUtility(item:Object):Boolean {
// pass back whether the location square foot is with in the range specified

if((item.SQUARE_FOOTAGE >= rangeText1.text) && (item.SQUARE_FOOTAGE rangeText2.text))
    return item.SQUARE_FOOTAGE;
} 

// THIS WOULD BE CALLED WHEN COMBO BOX SELECTION IS DONE 
private function selectLocationsReports(event:ListEvent):void {
    selectedItem =(event.currentTarget as ComboBox).selectedItem.LOCATION_ID;
}

When the DataProvider gets refreshed its automatically calls change method and was throwing Null Pointer function because its prematurely calling the above selectLocationsReports method and its throwing error.

Can somebody let me know how to stop the CHANGE event from propogation when the dataprovider is refreshed.

A: 

You can't stop a CHANGE event, just don't add an event listener unless you are prepared to get the event. I don't see where your event listener for Event.CHANGE is in the code above.

Just be sure that you don't addEventListener(Event.CHANGE, selectLocationsReports) until your ComboBox is ready for it.

Kekoa
A: 

The other thing to do (on top of Kekoa's response) is put an if statement in the event handler, and check to make sure the data is there before you begin working with it.

Tyler Egeto
A: 

A handy syntax I use frequently for this is

if(dataprovidername) {

}

le dorfier