Thursday, March 13, 2008

Populating ComboBox with ArrayCollection

Another thing I always forget: I have a RemoteObject that calls a database and returns the result into an ArrayCollection. The resultHandler function looks like this:

private var songsArr:ArrayCollection;

private function returnSongsHandler(e:ResultEvent):void
{
songsArr = e.result as ArrayCollection;
cbSongs.dataProvider = songsArr;
}

In addition to setting the dataProvider for the ComboBox, it is also necessary to set the labelField for the cb. Otherwise, you will see [object][object] in the menu. So, the ComboBox tag should look like:

labelField="songTitle"

This uses the songsArr ArrayCollection as a dataProvider, and displays the songTitle field of the array collection.

No comments: