Tip: Embedding fonts in Flex
4 posts • Page 1 of 1
Tip: Embedding fonts in Flex
When you are working with fonts, getting them to embed and work properly is a bit of a nightmare.
Step one is to embed them in a Flex CSS file like this:
You can also embed a font symbol from a SWF file.
Step two is to list the fonts the SWF thinks it has in it:
Step three is to use it to style something:
Step one is to embed them in a Flex CSS file like this:
- Code: Select all
@font-face
{
src:url("../Assets/HUM521XB.TTF");
fontFamily: "Humanst Bold";
advancedAntiAliasing: true;
fontWeight: bold;
}
You can also embed a font symbol from a SWF file.
Step two is to list the fonts the SWF thinks it has in it:
- Code: Select all
// Debug aid - note all our fonts.
var fontList:Array = Font.enumerateFonts(false);
for (var i:uint=0; i<fontList.length; i++)
Logger.Print(this, "Font: "+fontList[i].fontName + " " + ObjectUtil.toString(fontList[i]));
Step three is to use it to style something:
- Code: Select all
Button.MenuButton
{
fontFamily: "Humanst Bold";
fontSize: 30;
advancedAntiAliasing: true;
color: #FFFFFF;
textSelectedColor: #FFFFFF;
textRollOverColor: #FFFFFF;
}
Ben Garney PushButton Labs
-
bengarney - Employee
- Posts: 1519
- Joined: Wed Jan 14, 2009 7:21 pm
- Location: Eugene, OR
Re: Tip: Embedding fonts in Flex
There is even a step 4 if one is working on a actionscript only project in Flex Builder.
Declare your embedded font in the variable declaration section of your main class
Don't forget to use the font as embedded , otherwise it will not be embedded into your SWF.
Declare your embedded font in the variable declaration section of your main class
- Code: Select all
[Embed(source="C:\\WINDOWS\\Fonts\\TEMPSITC.TTF", fontFamily="Tempus Sans ITC")]
private var _TEMPUS_str:String
Don't forget to use the font as embedded , otherwise it will not be embedded into your SWF.
- Code: Select all
var myFormat:TextFormat = new TextFormat("Tempus Sans ITC", 18, 0x000000);
var font : TextField = new TextField();
font.defaultTextFormat = myFormat;
font.embedFonts = true;
Martijn Segers - Makeyourflashgame.com
“The intuitive mind is a sacred gift and the rational mind is a faithful servant. We have created a society that honors the servant and has forgotten the gift.” - Albert Einstein
“The intuitive mind is a sacred gift and the rational mind is a faithful servant. We have created a society that honors the servant and has forgotten the gift.” - Albert Einstein
-
mas - Rock Star
- Posts: 236
- Joined: Tue Jun 30, 2009 7:45 am
- Location: Berlicum, The Netherlands
Re: Tip: Embedding fonts in Flex
mas wrote:There is even a step 4 if one is working on a actionscript only project in Flex Builder.
But don't forget to add '-fonts.managers manager class [...]' to your additional compiler options or transcoding can't occur.
Also, if you're using Ant you need to add the following inside the mxmlc task:
- Code: Select all
<fonts>
<manager class="flash.fonts.AFEFontManager"/>
</fonts>
Other font managers can be found here: http://livedocs.adobe.com/flex/3/html/help.html?content=fonts_06.html
web: philperon.com----- twitter: @pperon
"Media that's targeted at you but doesn't include you may not be worth sitting still for." -Clay Shirky
"Media that's targeted at you but doesn't include you may not be worth sitting still for." -Clay Shirky
-
phil - Rock Star
- Posts: 216
- Joined: Thu Apr 23, 2009 4:47 pm
- Location: Shaker Heights, OH
Re: Tip: Embedding fonts in Flex
Whoa, great info, guys. I will definitely be referring to this in the future. 
Ben Garney PushButton Labs
-
bengarney - Employee
- Posts: 1519
- Joined: Wed Jan 14, 2009 7:21 pm
- Location: Eugene, OR
4 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest