Embedding fonts for AS3. How?

2019-05-25 08:25发布

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?

2条回答
男人必须洒脱
2楼-- · 2019-05-25 08:34
  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

查看更多
ら.Afraid
3楼-- · 2019-05-25 08:41

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"

查看更多
登录 后发表回答