# \[AS3\] Embedding multiple members of a font-family

**URL:** https://forum.kirupa.com/t/as3-embedding-multiple-members-of-a-font-family/223031
**Category:** flash
**Created:** [April 18, 2007, 9:15pm UTC](https://forum.kirupa.com/t/as3-embedding-multiple-members-of-a-font-family/223031 "2007-04-18T21:15:02Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ego](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@Ego](https://forum.kirupa.com/u/Ego)
#### Post date: [April 18, 2007, 9:15pm UTC](https://forum.kirupa.com/t/as3-embedding-multiple-members-of-a-font-family/223031/1 "2007-04-18T21:15:02Z")

</div>

I’ve been compiling Actionscript 3 in Flex Builder a while now. Love the platform but I’ve run into a problem that doesn’t seem to be documented enough and I really can’t find a solution.

In Flex/AS3 font embedding has been totally revamped. You have to use the Embed tag. Simple embedding of a single font isn’t a problem but when I try to embed multiple members of a font family, I get into trouble.

I want to embed Helvetica and Helvetica Bold in one of my projects. Embedding Helvetica isn’t a problem but I can’t get the bold to work.

If I just embed the bold font I get this error:

```auto
exception during transcoding: Font for alias 'Helvetica LT Std' with plain weight and style was not found at: file:/c:/GFX/fonts/HelveticaLTStd-Bold.ttf

```

Now I got it working in one project this way:

```auto
[Embed(source='fonts/HelveticaLTStd-Bold.ttf', source='fonts/HelveticaLTStd-Roman.ttf', fontFamily="Helvetica LT Std", mimeType="application/x-font-truetype")] 
private static var FONT_HELVETICA:String;

```

**But** when I copied the exact code to another project and moved the fonts folders with it and recompiled. It didn’t work! When I recompiled the project where it worked it still worked. But ever since that one project I haven’t been able to get it working. I’ve got the feeling Flex is extremely buggy in this aspect.

So, how do I embed multiple parts of a font-family in Actionscript 3, compiled with Flex?

PS: Sorry for my sloppy English.

---

<div class="post-metadata">

### Author: ![justsomeguy](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@justsomeguy](https://forum.kirupa.com/u/justsomeguy)
#### Post date: [July 4, 2008, 5:36am UTC](https://forum.kirupa.com/t/as3-embedding-multiple-members-of-a-font-family/223031/2 "2008-07-04T05:36:58Z")

</div>

I’ve been googling for half a day and pulling a lot of hair out until I found this post.  
I thought I’d summarize this great bit of wisdom with some key words for anyone else searching out there.  
Specifically, in my case I had issues with using multiple fonts with CSS in an HTML textfield.

\*\*The Setup  
\*\*  
You’re using AS3/CS3/Flex/mxmlc. You’ve got some texfields with HTML code and a little CSS for good clean markup. You’d like to embed some fonts to make sure things appear consistently on any platform.

**The Problem**

After learning about the “Embed” meta tag you’ve managed to embed a font and display it. But variations of fonts (bold, italic) come in different files and you can’t get them to work at the same time in a single text field.

After some thinking you decided to embed several fonts under the same family name, like so:

```auto

[Embed(source="../fonts/Verdana.ttf", fontWeight="normal", fontName="VerdanaRegular", fontFamily="Verdana", mimeType="application/x-font-truetype")]
public static const VerdanaRegularTTF:String;

[Embed(source="../fonts/Verdana_Bold.ttf", fontWeight="bold", fontName="VerdanaBold", fontFamily="Verdana", mimeType="application/x-font-truetype")]
public static const VerdanaBoldTTF:String;

```

Then you try to pass the fontFamily to CSS:

```auto

...
var defaultStyle:Object = new Object();
defaultStyle.fontFamily="Verdana";

```

But this doesn’t work. CSS doesn’t recognize the fontFamily from the Embed tag; it only recognizes the fontName tag.

You also try to set a text format for your textfield (thinking of passing the fontFamily name with format.font=“Verdana”). But it seems that ‘format’ isn’t allowed with CSS.

**The Solution**

Use a single fontName for the fonts when embedding them. Pass this single fontName to CSS (you don’t need to include a fontFamily field). Also make sure to include the proper fontStyle/fontWeight fields when embedding italic/bold fonts. Finally, remember to set the “embedFonts” property to ‘true’ for your textfield.

Here are the important snippets. Embedding:

```auto

[Embed(source="../fonts/Verdana.ttf", fontName="Verdana", mimeType="application/x-font-truetype")]
public static const VerdanaTTF:String;

[Embed(source="../fonts/Verdana_Bold.ttf", fontWeight="bold", fontName="Verdana", mimeType="application/x-font-truetype")]
public static const VerdanaBoldTTF:String;

[Embed(source="../fonts/Verdana_Italic.ttf", fontStyle="italic", fontName="Verdana", mimeType="application/x-font-truetype")]
public static const VerdanaItalicTTF:String;

[Embed(source="../fonts/Verdana_Bold_Italic.ttf", fontWeight="bold", fontStyle="italic", fontName="Verdana", mimeType="application/x-font-truetype")]
public static const VerdanaBoldItalicTTF:String;

```

Using CSS with the textfield:

```auto

var defaultStyle:Object = new Object();
defaultStyle.fontFamily = "Verdana";

var style:StyleSheet = new StyleSheet();
style.setStyle(".defaultStyle", defaultStyle);

var t:TextField = new TextField();
t.embedFonts = true;
t.styleSheet = style;
t.htmlText = "<span class='defaultStyle'>My <b>bold</b> text</span>";

```

And you’re done.

---

<div class="post-metadata">

### Author: ![daidai](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/daidai/32/3087_2.png) [@daidai](https://forum.kirupa.com/u/daidai)
#### Post date: [July 4, 2008, 8:44am UTC](https://forum.kirupa.com/t/as3-embedding-multiple-members-of-a-font-family/223031/3 "2008-07-04T08:44:00Z")

</div>

how/why is using

[AS][Embed(source="…/fonts/Verdana\_Bold\_Italic.ttf", fontWeight=“bold”, fontStyle=“italic”, fontName=“Verdana”, mimeType=“application/x-font-truetype”)]  
public static const VerdanaBoldItalicTTF:String;[/AS]

better than adding the font to the FLA library and assigning the Font’s link, then declaring it in the code like in this example

[AS]myFormat.font = myFont.fontName;[/AS] (myFont being the embedded font, taken from [http://www.adobe.com/devnet/flash/quickstart/embedding\_fonts/#section1](http://www.adobe.com/devnet/flash/quickstart/embedding_fonts/#section1))

---

<div class="post-metadata">

### Author: ![justsomeguy](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@justsomeguy](https://forum.kirupa.com/u/justsomeguy)
#### Post date: [July 4, 2008, 8:09pm UTC](https://forum.kirupa.com/t/as3-embedding-multiple-members-of-a-font-family/223031/4 "2008-07-04T20:09:48Z")

</div>

I use the [Embed] tag because I’m using Flex2 SDK + mxmlc, not the Flash IDE – just pure plain text actionscript files (the compiler is free by the way and runs on Linux). Adding the font to the library should be equivalent, but I have no experience with it myself. Also, I can’t use myFormat.font for textfields with CSS styles attached because the compiler gives errors. So I use style.fontFamily=“Verdana” instead. So what you’re doing seems fine in your case, but won’t work for other situations.

---

<div class="post-metadata">

### Author: ![daidai](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/daidai/32/3087_2.png) [@daidai](https://forum.kirupa.com/u/daidai)
#### Post date: [July 4, 2008, 11:47pm UTC](https://forum.kirupa.com/t/as3-embedding-multiple-members-of-a-font-family/223031/5 "2008-07-04T23:47:33Z")

</div>

[QUOTE=justsomeguy;2353743]I use the [Embed] tag because I’m using Flex2 SDK + mxmlc, not the Flash IDE – just pure plain text actionscript files (the compiler is free by the way and runs on Linux). Adding the font to the library should be equivalent, but I have no experience with it myself. Also, I can’t use myFormat.font for textfields with CSS styles attached because the compiler gives errors. So I use style.fontFamily=“Verdana” instead. So what you’re doing seems fine in your case, but won’t work for other situations.[/QUOTE]  
ok, thanks
