Using embedded fonts with the Flash CS3 Button control

The following example shows how you can use embedded fonts (normal weight and bold weight) with a Flash CS3 Button control.

Full code after the jump.

const STR:String = "The quick brown fox";var f2:Font = new EmbeddedVerdana() as Font;var f3:Font = new EmbeddedVerdanaBold() as Font;var tf1:TextFormat = new TextFormat();tf1.font = "Verdana";var tf2:TextFormat = new TextFormat();tf2.font = f2.fontName; // Verdanavar tf3:TextFormat = new TextFormat();tf3.font = f3.fontName; // Verdanatf3.bold = true;button1.label = STR;button1.setStyle("textFormat", tf1);button2.label = STR;button2.setStyle("embedFonts", true);button2.setStyle("textFormat", tf2);button3.label = STR;button3.setStyle("embedFonts", true);button3.setStyle("textFormat", tf3);

Download FLA

8 Responses to Using embedded fonts with the Flash CS3 Button control

  1. peterd says:

    The link is a little buried above (it is above the SWF), but you can download the FLA file at http://blogs.adobe.com/pdehaan/uploads/embeddedfonts/main.fla if you want to see how I embedded the fonts in my Flash document’s library.Peter

  2. Kevin Newman says:

    That’s great! Now all we need is a way to replace all instances of Agenda-Bold with Agenda-Regular with the bold button pressed (a common problem when you move a .fla from Mac to Windows). It’s currently impossible to do (then there’s the three pixel jump).Sorry to hijack this thread (feel free to keep this comment private), but it’s really time to overhall Flash’s Font system – especially the way it groups OpenType fonts – which is completely different on Windows and Mac – Mac gets it right.

  3. peterd says:

    Kevin,You can file bug reports and feature requests for many Adobe products (and Flash specifically) at: http://www.adobe.com/go/wish?product=15.NOTE: Flex bugs can be filed at http://bugs.adobe.com/flex/.Peter

  4. Peter Hesterman says:

    I sure would like to see an example that applies this technique to a Flash CS3 ComboBox component. I can’t get it to work–at least not in a way that will let me use some of the special characters I need from the font (some musical symbols).

  5. Peter Hesterman says:

    I sure would like to see an example that applies this technique to a Flash CS3 ComboBox component. I can’t get it to work–at least not in a way that will let me use some of the special characters I need from the font (some musical symbols).Peter

  6. peterd says:

    Peter,This should do the trick (or get you closer, hopefully):import fl.controls.ComboBox;import fl.data.DataProvider;var font:Font = new VerdanaEmbedded() as Font;var tf:TextFormat = new TextFormat();tf.font = font.fontName;var arr:Array = new Array();arr.push({label:”One”});arr.push({label:”Two”});arr.push({label:”Three”});arr.push({label:”Four”});arr.push({label:”Five”});arr.push({label:”Six”});var cb:ComboBox = new ComboBox();cb.dropdown.setRendererStyle(“embedFonts”, true);cb.dropdown.setRendererStyle(“textFormat”, tf);cb.dataProvider = new DataProvider(arr);cb.move(10, 10);addChild(cb);Peter

  7. Andrew says:

    I’m having a little trouble with embedded fonts not showing up when buttons are disabled.Your example seems to have the same problem. Do you have any pointers?Thanks

  8. peterd says:

    Andrew,I believe you need to set the disabledTextFormat style, as seen in the following example:import fl.controls.Button;var embeddedVerdana:Font = new EmbeddedVerdana() as Font;var defaultFmt:TextFormat = new TextFormat();defaultFmt.font = embeddedVerdana.fontName;defaultFmt.bold = true;var buttonEnabled:Button = new Button();buttonEnabled.setStyle(“textFormat”, defaultFmt);buttonEnabled.setStyle(“embedFonts”, true);buttonEnabled.move(10, 10);buttonEnabled.rotation = 15;addChild(buttonEnabled);var buttonDisabled:Button = new Button();buttonDisabled.setStyle(“textFormat”, defaultFmt);buttonDisabled.setStyle(“disabledTextFormat”, defaultFmt);buttonDisabled.setStyle(“embedFonts”, true);buttonDisabled.enabled = false;buttonDisabled.move(10, 50);buttonDisabled.rotation = 15;addChild(buttonDisabled);