Setting the font name and size in AS3 List control (flash.controls.List)

Paul Chernoch picture Paul Chernoch · Jun 26, 2009 · Viewed 9.4k times · Source

Using CS4, how do I set the font of a List control? I tried this:

        var myFormat:TextFormat = new TextFormat();
        myFormat.font = config.settings["list font name"];
        myFormat.size = Number(config.settings["list font size"]);
        list.setStyle("textFormat", myFormat);

No dice.

Answer

George Profenza picture George Profenza · Aug 29, 2009

You can set styles by instance, class and globally.

For selectable lists(List,ComboBox,TileList,etc.), you need to use setRendererStyle instead of setStyle, because you're setting styles for each cell renderer/item, not the list itself, if that makes sense:

list.setRendererStyle('textFormat',myFormat);

Also you can use global styles using StyleManager.

Make sure your fonts is embedded first, then try

import fl.managers.StyleManager;

var myFormat:TextFormat = new TextFormat(config.settings["list font name"],config.settings["list font size"]);
StyleManager.setStyle('embedFonts',true);
StyleManager.setStyle('textFormat',myFormat);