ComboBox items Styling

70 Views Asked by At

I have a ComboBox that contains the names of some fonts, if the user chooses an item (a font), the text inside a text field changes to the corresponding font.

I just want to display each font in the item that holds it, similar to microsoft word: https://i.stack.imgur.com/qGRsz.png

Not what i have here, the same font for all of them: https://image.ibb.co/ca55qR/combobox.png

I tried the following:

var tf:TextFormat = new TextFormat();
tf.font = "Tahoma";
tf.size = 12;
myFontsBox.textField.setStyle("textFormat", tf);

the "Tahoma" font is applied to every item in the ComboBox, the desired result is for it to be applied only on the "Tahoma" item.

Is there any way i can change the styling of the items inside the ComboBox ??

1

There are 1 best solutions below

0
Kyle Delaney On

You could try something like this:

var dropdown:List = myFontsBox.dropdown;
for (var i:int = 0; i < dropdown.length; i++)
{
    var item = dropdown.getItemAt(i);
    var tf:TextFormat = new TextFormat();
    tf.font = dropdown.itemToLabel(item);
    tf.size = 12;
    item.setStyle("textFormat", tf);
}