Add an event listener to filter the gift ideas

In this section, you add an event listener to detect when a user selects an offense in the What Did You Do? section (the problems_cb ComboBox instance). The listener includes a function that filters the Gift Ideas list according to the offense the user chooses. Selecting a minor offense displays a list of modest gifts (such as a CD or flowers); selecting a more serious offense displays more opulent gifts.

For more information on working with event listeners, see Using event listeners in Learning ActionScript 2.0 in Adobe Flash.

Resetting the filtered property (setting it to false and then to true) at the beginning of the change() function ensures that the function will work properly if the user changes the What Did You Do? selection repeatedly.

The filterFunc() function checks whether a given item in the array of gifts falls within the severity the user selected in the combo box. If the gift is within the selected severity range, it is displayed in the DataGrid instance (which is bound to the DataSet instance).

The last line of code registers the listener to the problems_cb ComboBox instance.