Thursday, September 1, 2011

Font embedding Flex 4.5 (actionscript 3)


After working for a few hours on a brand new all customizable slideshow I'm developing for a website, I decided I wanted to embed some fonts into my code.
This is easy stuff, but my friends, there's a catch, reading around the internet I found there might be a bug with the transcoder.
The embedding code is the following
[Embed(source='assets/My Font.ttf',
fontName='myFont',
embedAsCFF='true'
)]
private var MyFont :Class;
Then you just have to use
textFormatter.font = myFont;
Last, but not least, in order for the transcoder to work nicely you will have to add the following lines into the flex-config under the compiler tag


<fonts>

  <managers>

     <manager-class>flash.fonts.AFEFontManager</manager-class>

     <manager-class>flash.fonts.BatikFontManager</manager-class>

     <manager-class>flash.fonts.JREFontManager</manager-class>

  </managers>

</fonts>


The actual font manager that's working is the AFEFontManager, so that's the one we want on the top. Though I read somewhere that some people managed to get it to work by changing the managers position on the list.

Don't forget to use


myTextField.embedFonts = true;

Another thing, I've seen that not all the fonts work, usually ttf will work but not always though. If anyone can explain me why is that it would be great.