PDA

View Full Version : List Component + Embed


Mr.Kennedy
11-24-2008, 01:10 PM
Hello everyone, well im pretty pretty new to AS3 world. Im not a great mind for programming so everything i do takes me a lot of time to figure it out.

Scenerio: I have a List Component, and i need to use an embed font on the list. So far i figured out how to format most of the List Component using a Custom CellRenderer like this:

package {
import fl.controls.listClasses.CellRenderer;
import flash.text.TextFormat;
import flash.filters.BevelFilter;
import flash.text.TextField;

public class CustomCellRenderer extends CellRenderer {

public function CustomCellRenderer() {
var format:TextFormat = new TextFormat();
format.font = "capitan"; // this is the font name imported to library
format.size = 16;
format.leftMargin = 18;
setStyle("textFormat", format);

}

}
}

called CustomCellRenderer.as

and i have my .fla file with a List Component on stage (instance name: playList). with this code in the first frame to get the style from the .as file:

playList.setStyle("cellRenderer", CustomCellRenderer);
playList.rowHeight = 30;
playList.setStyle("embedFonts", true);

So far, it does in fact format the text on the list, but it doesnt use the embed font. What im missing on this situation?.

Thanks in adv!.

Mr.Kennedy
11-24-2008, 04:22 PM
:D

I found the solution, stupid me!

i was missing 3 simple lines

package {
import fl.controls.listClasses.CellRenderer;
import flash.text.TextFormat;
import flash.filters.BevelFilter;
import flash.text.TextField;
import flash.text.Font;

public class CustomCellRenderer extends CellRenderer {

public function CustomCellRenderer() {
var font:Font = new capitan(); //from library
var format:TextFormat = new TextFormat();
format.font = font.fontName;
format.size = 24;
format.leftMargin = 18;

var tf:TextField = new TextField();
tf.embedFonts = true;
tf.defaultTextFormat = format;

setStyle("textFormat", format);

}

}
}

hope that this could help someone in the future :)