Using embedded fonts with the Flash CS3 DataGrid component

A reader asked me the other day if it was possible to embed fonts into a Flash CS3 DataGrid control’s HeaderRenderer in an ActionScript 3.0 project.

After a bit of code shuffling, it seems it is possible. The trick was I had to create a HeaderRenderer instance and set the embedFonts style to true. Next, I set the row renderer’s embedFonts style to true and the textFormat style using the setRendererStyle() method, and finally set the headerTextFormat style using the setStyle() method.

Full code after the jump.

import fl.controls.dataGridClasses.DataGridColumn;import fl.controls.dataGridClasses.HeaderRenderer;import fl.data.DataProvider;var f1:Font = new VerdanaEmbedded() as Font;var headerTF:TextFormat = new TextFormat();headerTF.bold = false;headerTF.font = f1.fontName; // VerdanaheaderTF.size = 16;var rowTF:TextFormat = new TextFormat();rowTF.bold = false;rowTF.font = f1.fontName; // VerdanarowTF.size = 9;var fontArr:Array = Font.enumerateFonts(true);fontArr.sortOn("fontName", Array.CASEINSENSITIVE);var headRen:HeaderRenderer = new HeaderRenderer();headRen.setStyle("embedFonts", true);var fontNameCol:DataGridColumn = new DataGridColumn("fontName");fontNameCol.headerText = "fontName:";fontNameCol.headerRenderer = headRen;dataGrid.setRendererStyle("embedFonts", true);dataGrid.setRendererStyle("textFormat", rowTF);dataGrid.setStyle("headerTextFormat", headerTF);dataGrid.columns = [fontNameCol];dataGrid.dataProvider = new DataProvider(fontArr);dataGrid.rotation = 10;dataGrid.rowCount = 10;

Download FLA

Not sure if it is the “best” way, but it was the first solution I came up with. Any other tips/suggestions? Leave them in the comments!

3 Responses to Using embedded fonts with the Flash CS3 DataGrid component

  1. peterd says:

    For an example of how to do this in Flex, see “Using embedded fonts in a Flex DataGrid control”.Peter

  2. randy says:

    I am trying to get the datagrid so that it changes the font color of a row when I mouse over that row. Seems like a simple thing to do but I have not been able to find any information on how to do it. I can return the row and column index using ListEvent.ITEM_ROLL_OVER event. Is there a way to change that specific cells format on rollover? I am not finding much info on CellRenderer but it seems the way to go. Any help would be appreciated

  3. Roman says:

    is it possible to activate the antialias in advanced mode vor the header renderer? I tried but it seemd not to work.headRen.textField.antiAliasType = AntiAliasType.ADVANCED;Anybody an idea?