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

actionscript-3, flash-cs4, fonts

Solution

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);

Problem

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.

Original source