views:

116

answers:

2

Hi,

I have some issue with the [embed] tag. Even if I set the embedFonts property of the textfield to true the text doesn't show up.

The thing is that it worked previously and after some changes (not related to fonts) it doesn't. I'd like to understand how the embed process for font works to find the error in my code.

I declare :

[Embed(source = 'asset/font.ttf', fontName="font", mimeType="application/x-font-truetype")] private static var font:String;

to assign the font to the program.

Then i call "font" when declaring my textFormat. Is the "fontName" property the link with the textformat ?

I work with flashdevelop and the flex_sdk_4.0.0.14159 (the big adobe one, with air (~140mo))

Thx !

-Leg

+2  A: 

This can be a tricky thing to get just right. I had to fight with this about 10 days ago and only though trying several combinations of names and parameters to the embed could I get it to work.

I read blog reports that had anecdotal advice that you had to include the fontStyle if you need bold or whatnot. Here is the incantation that worked for me:

[Embed(source="assets/HelveticaBold.ttf",
       fontName="HelveticaBold",
       fontWeight="bold",
       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')]
private static var HelveticaBold:Class;

I don't think unicodeRange is strictly necessary but I didn't need the entire font and the above gives you the equivalent of "Basic Latin" in the IDE.

When I want to use the font I do so like this:

    var titleFormat:TextFormat = new TextFormat();
    titleFormat.font = "HelveticaBold";
    titleFormat.bold = true;
    titleFormat.color = 0x0;
    titleFormat.size = 18;

    var errorTitle:TextField = new TextField();
    addChild(errorTitle);
    errorTitle.embedFonts = true;
    errorTitle.autoSize = TextFieldAutoSize.LEFT;
    errorTitle.antiAliasType = AntiAliasType.ADVANCED;
    errorTitle.x = 5;
    errorTitle.y = 5;
    errorTitle.defaultTextFormat = titleFormat;

I can't believe I missed the most important piece. The above didn't work until I forced the mxmlc compiler to use a custom font manager.

Add the following as a compiler option:

-managers=flash.fonts.AFEFontManager

There is an Adobe technote on troubleshooting fonts in Flex 3 that lists the available font managers. Try them until you find one that works.

James Fassett
fontName or fontFamily in the [embed] tag : does it matter ?If I add the manager line to the compiler option it return an error : "couldn't find the specified file".This is very tricky :/
Legogo
After everything else on the net, the compiler flag finally solved it for me.
JoeCoder
A: 

The problem was coming from a modification in the 4.0 Flex SDK

http://opensource.adobe.com/wiki/display/flexsdk/Font+Embedding+Reprise

I set the compatibility to Flash player 9 (with sdk 3.4) and it is working again.

Legogo