ComboBox.selectedItem is looking for an Object. You are passing it a String literal. Where is "stylename" being set? If this is coming from an external source, you can retrieve the item to be selected in a setter function:
ActionScript 3:
[Bindable]
public var comboBoxData:ArrayCollection;
[Bindable]
private var comboBoxSelectedItem:Object = {};
private var _styleName;
private function get styleName():String
{
return _styleName;
}
private function set styleName(value:String):void
{
_styleName = value;
comboBoxSelectedItem = getItemFromCollection("styleName", value);
}
private function getItemFromCollection(property:String, value:String):Object
{
// Create a copy of the Collection used as the dataProvider for the ComboBox
var filteredCollection:ArrayCollection =
new ArrayCollection(comboBoxData.toArray());
// Set a filterFunction to filter only those Objects with the specified name/value pair
filteredCollection.filterFunction =
function(item:Object):Boolean
{
return item[property] == value;
}
// Refresh the collection to apply the filterFunction
filteredCollection.refresh();
// Return an empty Object if no Object was found with the given name/value pair
if (filteredCollection.length == 0)
return {};
// Return the first/only Object in the filtered Collection
return filteredCollection.getItemAt(0);
}
MXML:
<mx:ComboBox dataProvider="{comboBoxData}" selectedItem="{comboBoxSelectedItem}" />