Dependent ComboBox

Dependent ComboBox

Post by fizbea » Tue, 22 Jul 2008 13:44:42

You can do this by filtering the dataprovider for your secondary combobox. If
the dataprovider is an array you can use array.filter() and if it's an
arraycollection you can set array.filterFunction. Here's a really simple
example with two comboboxes, the first with states and the second with cities.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=" " layout="absolute"
<mx:ComboBox id="statesCombo" dataProvider="{statesDP}"
<mx:ComboBox id="citiesCombo" dataProvider="{citiesDP}"/>


import mx.collections.ArrayCollection;

[Bindable] public var citiesDP:ArrayCollection;
[Bindable] public var statesDP:ArrayCollection;

public function init() : void {

statesDP = new ArrayCollection([
{label:"Alabama", data:"AL"},
{label:"California", data:"CA"},
{label:"Texas", data:"TX"}
citiesDP = new ArrayCollection([
{label:"Mobile", state:"AL"},
{label:"Berkeley", state:"CA"},
{label:"San Diego", state:"CA"},
{label:"Palo Alto", state:"CA"},
{label:"Austin", state:"TX"}

public function filterCities() : void {

citiesDP.filterFunction = filterFunction;


public function filterFunction(item:Object):Boolean {

return (item.state ==;