4

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.

Paul Chernoch
  • 5,275
  • 3
  • 52
  • 73
  • I have not figured out how to set the font yet, but I did find an excellent example of how to make the colors on alternating rows of the list to vary in color: http://www.actionscript.org/forums/showthread.php3?t=188206 (It was different in AS2 - just needed one line. Now you need one line plus three whole classes.) – Paul Chernoch Jun 26 '09 at 21:13

3 Answers3

5

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);
George Profenza
  • 50,687
  • 19
  • 144
  • 218
0

This took me a long time to figure out, sadly:
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/fl/controls/SelectableList.html#setRendererStyle()

0

It seems the answers above are rather old, and they no longer worked for me... The link Will Mavis provided doesn't open anymore either.

Anyway, I found a way that worked for me (on Flash CS6): (and as written above, don't forget to embed your font)

import fl.managers.StyleManager;
import flash.text.TextFormat

var myFormat:TextFormat = new TextFormat();
myFormat.font = "Arial";  // your font
myFormat.size = 20;  // your font size
myList.setRendererStyle('textFormat',myFormat);
myList.rowHeight = 30;  // if you want to change the row height (to better match the text size)
Koby.G
  • 73
  • 9