2

I embedded font using Flash Professional CS5, but I still can't use it in my AS code. How should I embed the font to be able to use it in AS3 as well in Flash Professional CS5?

nicks
  • 2,161
  • 8
  • 49
  • 101

2 Answers2

6

I do something slightly more different. :D embedAsCFF should be false if you wish to use old TextFields or true of you use the new text engine.

public class Font_Arial
{

    [Embed(source   = 'Arial.ttf'
    ,fontFamily     ='_Arial_'
    ,fontStyle      = 'normal'  // normal|italic
    ,fontWeight     = 'normal'  // normal|bold
    ,mimeType       = "application/x-font-truetype"
    ,unicodeRange   = 'U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E'
    ,embedAsCFF     = 'false'
    )]
    private const _regular:Class;

    [Embed(source   = 'Arial_i.ttf'
    ,fontFamily     ='_Arial_'
    ,fontStyle      = 'italic'  // normal|italic
    ,fontWeight     = 'normal'  // normal|bold
    ,mimeType       = "application/x-font-truetype"
    ,unicodeRange   = 'U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E'
    ,embedAsCFF     = 'false'
    )]
    private const _italic:Class;

    [Embed(source   = 'Arial_b.ttf'
    ,fontFamily     ='_Arial_'
    ,fontStyle      = 'normal'  // normal|italic
    ,fontWeight     = 'bold'    // normal|bold
    ,mimeType       = "application/x-font-truetype"
    ,unicodeRange   = 'U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E'
    ,embedAsCFF     = 'false'
    )]
    private const _bold:Class;

    [Embed(source   = 'Arial_bi.ttf'
    ,fontFamily     ='_Arial_'
    ,fontStyle      = 'italic'  // normal|italic
    ,fontWeight     = 'bold'    // normal|bold
    ,mimeType       = "application/x-font-truetype"
    ,unicodeRange   = 'U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E'
    ,embedAsCFF     = 'false'
    )]
    private const _boldItalic:Class;

    public static const name:String = "_Arial_";

    public function Font_Arial()
    {
        Font.registerFont(_regular);
        Font.registerFont(_italic);
        Font.registerFont(_bold);
        Font.registerFont(_boldItalic);
    }
}

Then you can use something like

var _format:TextFormat = new TextFormat(Font_Arial.name, 16,....)

You will need to make sure the name static constant is identical to the fontFamily within the font. They are all given the same name so they all act as 1 font, the textfield will pick the correct style to use if the textfield is set to bold or italic or bold and italic or just plain old regular.

I would then make a different class for different font "sets"

WORMSS
  • 1,625
  • 28
  • 36
  • PS: you will need to place Arial.ttf in the same folder as the class. – WORMSS Sep 14 '11 at 10:28
  • Don't forget to set your textfields to myTextField.embedFonts = true; – Randalfien Oct 02 '12 at 07:49
  • Oh yes, that is very true. I forget to mention that as I use an extended TextField class that turns it on/off when font is changed by reading Font.enumerateFonts() – WORMSS Oct 02 '12 at 13:56
1
  1. Embed the font inside your fonts.fla file. http://www.adobe.com/devnet/flash/quickstart/embedding_fonts.html

  2. Export fonts.fla to the SWC library. ( under export settings check the SWC box in Flash CS5 )

  3. Use the swc with the code!

Then you should be able to see it:

enter image description here

Jevgenij Dmitrijev
  • 2,228
  • 1
  • 15
  • 23