Paul Chernoch
Paul Chernoch

Reputation: 5553

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

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.

Upvotes: 4

Views: 9504

Answers (3)

Koby.G
Koby.G

Reputation: 95

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)

Upvotes: 0

George Profenza
George Profenza

Reputation: 51837

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

Upvotes: 5

Will Mavis
Will Mavis

Reputation: 9

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

Upvotes: 0

Related Questions