(…and breaks the way everyone has been doing it with ActionScript).
Basically, no longer do you embed a font like this:
Flash CS5 brings along with it a new item in the Text menu for your FLA. Simply select Text, and go down to Font Embedding:
Once selected, hit the plus to create a new font entry, and customize it as you desire (weights, embedded glyphs, etc). If you don’t need to reference it from ActionScript, you’re finished, but if you do, read on…
Hit the ActionScript tab, and check off Export for ActionScript (if the base class is not set, type in flash.text.Font).
Now you’re font is embedded with the glyphs of your choosing, but you’re not finished. Now you need to include this code (replace NumberFont with your linkage name from before):
import flash.text.Font;
…
Font.registerFont(NumberFont);
Now you can reference your font in a variety of ways, but not with the name “NumberFont”. Since I embedded Arial Bold, if you use a stylesheet it should be:
font-family: “Arial” (ActionScript property: fontFamily = “Arial”)
and
font-weight: “bold” (ActionScript property: fontWeight = “bold”)
If you’re using a TextFormat, it should be:
new TextFormat(“Arial”, 10, 0×000000, true)
Would have been nice to know this change was happening (specifically that the old way would stop working) rather than pop open an FLA and be blindsided by it, but it’s an easy fix and a nicer implementation as far as I’m concerned. That said, this probably creates problems for people who want to be able to build without Flash and keep their code portable for people who do build with Flash.



#1 by Fabian Irsara on May 23, 2010 - 10:45 am
Doesn’t work for me.
If i put my Text to the stage it’s gone, i can select it but it’s “invisible” and when i set my TextField’s embedFonts property to false I get a default system Font….
#2 by Aaron on May 26, 2010 - 10:14 am
Are you generating the TextField entirely with ActionScript? Unlike before, you don’t use the linkage term to denote the font you want to display, so that might be the issue. Then there are complications with style variants and whether or not the font supports them and how you should reference them. If you could tell me which font, style, etc, I could probably put something together that will work.
#3 by Nolan on May 27, 2010 - 3:50 pm
I’m running into this exact same problem, only I’m trying to compile with AS2 & Flash 8 since I’m making online ads. Is the procedure the same for embedding fonts? I had everything working smoothly in CS3, and CS5 broke it.
#4 by Nolan on May 27, 2010 - 5:09 pm
Hi Aaron,
So it looks like compiling with AS2/Flash8 I am able to get the base MyriadPro font to display and dynamically change simply by embedding the font using the embed dialog, and referencing the embedded font (“Myriad Pro*”) under Family in the Properties panel.
If I try to use an embedded font with style (Myriad Pro Bold or Myriad Pro Bold Italic), the static text I use in the field displays with style until I change the contents dynamically, at which point the style is lost, and unstyled Myriad Pro displays.
Do you know how to reference styled embedded fonts within AS2 for use in dynamic text elements?
Thanks,
Nolan
#5 by Aaron on May 27, 2010 - 5:25 pm
I haven’t played with AS2 recently, but I’ll take a look and get back to you.
#6 by Fabian Irsara on May 30, 2010 - 6:33 am
Ok now i managed to embed them.
But there’s one more thing i struggle with:
is there any way I can give my embedded font a unique font-family name to use on my TextFormat?
it’s not actually a problem, but some fonts really have some strange names (eg.Titilium: TitilliumText14L 600 wt, TitilliumText14L Bold, …)
I’d like to give it simply the name: “Titilium light”, “Titilium Regular”, …
#7 by Aaron on May 30, 2010 - 8:27 am
For that, I believe you need to modify the font. The application I use for all my font adjustment needs is FontForge.
#8 by Dane on June 16, 2010 - 1:11 am
it’s not working for me either. my website successfully used css text in CS4, and when i upgraded to CS5 and exported, it was broken. no css text. i added the “import flash.text.Font;” and “Font.registerFont(UniversBC); Font.registerFont(UniversBCO); Font.registerFont(UniversLC); Font.registerFont(UniversLCO)” for the 4 fonts i was using, and its still a no-go. i haven’t changed the css at all, and i dont get any compiler errors. any ideas?
#9 by DouG Molidor on June 18, 2010 - 12:56 am
This worked for me. Thanks!
CS5′s method is more semantic, but still not perfect.
I was able to migrate CS4 to CS5 real quick by using your CSS implementation. It’s odd that for regular style font I have to use the font-family “Helvetica Neue LT Std 55 Roman”, but for bold, the font family is “HelveticaNeueLT Std”.
FROM (CS4):
.formFieldLabel {
font-family: “Helvetica Neue LT Std 55 Roman”;
font-size: 12 px;
color: #444444;
}
.formFieldValue {
font-family: “Helvetica Neue LT Std 75 Bold”;
font-size: 14 px;
color: #444444;
text-padding: 7 px;
}
TO (CS5):
.formFieldLabel {
font-family: “Helvetica Neue LT Std 55 Roman”;
font-size: 12 px;
color: #444444;
}
.formFieldValue {
font-family: “HelveticaNeueLT Std”;
font-weight: bold;
font-size: 14 px;
color: #444444;
text-padding: 7 px;
}
#10 by Aaron on June 18, 2010 - 7:34 am
I’m sorry for not getting back to people sooner, things have gotten pretty busy for me lately and I’ve been completely preoccupied.
One general suggestion that popped into my mind after DouG Molidor’s comment is that it’s possible that the way the font is being referenced is incorrect. I suggest a copy of FontForge which runs via X11 in OS X (sadly Cygwin in Windows).
You can open up pretty much any font in existence and go to Element->Font Info. From there you can grab all the information you need from the Names and TTF Names sections. and it will make it more clear what family name you need and the options available. Sometimes it’s a bit tricky to get working (if you’re dealing with a bold and italic font for example, the family might include one of the two variants in it). This kind of detail is normally in TTF Names as Preferred Family versus Family (Adobe Casion Pro Bold shows as Family: “Adobe Casion Pro Bold” and the Preferred Family is “Adobe Casion Pro”).
These fields will give you the names you’ll want to try.
#11 by julie on September 1, 2010 - 4:11 pm
Not working for me either. I am doing an update on CS5 to as2 code and the original will not compile without throwing an error saying: “Fonts should be embedded for any text that may be edited at runtime, other than text with the “Use Device Fonts” setting. Use the Text > Font Embedding command to embed fonts.” The embedded font was still there in the new font embedding window. I tried importing and then the exporting at run time options without luck. I changed the css file to have quotation marks around the font name and font style, in this case Arial bold (to make sure it would not be expecting an odd name). Nothing works. Ideas please?
#12 by julie on September 1, 2010 - 4:14 pm
Of course, I had to submit this past comment to go check and see it working. I am still getting the error message but the text is there so there must be something I still need to clean somewhere. Thanks guys!
#13 by steven on September 9, 2010 - 2:39 pm
Any chance someone can post a full code sample that works? I’m not having any luck and I’m seeing other posts around the web referencing this page where other people can’t get it to work.
#14 by Dane Hansen on October 17, 2010 - 5:07 pm
I have been searching for the solution to this for months and I still am not able to implement this css text on my personal website that once worked fine in CS4. I have set up a simpler test document, all empty on stage with 4 weights of Univers exported for ActionScript from the library. Here’s my code on the timeline:
/////
/////
/////
var css:StyleSheet;
function init():void
{
//these are the names of the 4 versions of Univers i have exported in my library. some sources say they must be registered, some say they dont.
/*Font.registerFont(UniversLC);
Font.registerFont(UniversLCO);
Font.registerFont(UniversBC);
Font.registerFont(UniversBCO);*/
//loads up the css page
var cssLoader:URLLoader=new URLLoader(new URLRequest(“test.css”));
cssLoader.addEventListener(Event.COMPLETE, cssLoaded, false, 0, true);
}
function cssLoaded(evt:Event):void
{
css=new StyleSheet();
css.parseCSS(evt.target.data);
//loads up the xml page
var xmlLoader:URLLoader=new URLLoader(new URLRequest(“test.xml”));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded, false, 0, true);
}
function xmlLoaded(evt:Event):void
{
var xmlData:XML=new XML(evt.target.data);
//creates the empty textfield
var tf:TextField=new TextField();
tf.multiline=true;
tf.width=tf.height=500;
addChild(tf);
//adds style and content to textfield
tf.styleSheet=css;
//some sources have said to add this line, some say not to:
//tf.embedFonts=true;
tf.htmlText=xmlData.here;
}
init();
/////
/////
/////
Locally, the text will show up in all 4 versions, but apparently it is not pulling the font from the library version but rather from what is installed on my system, as on most other computers all the text will show up as just Times. If I set the embedFonts to true, I get NO text, and whether or not I use the register fonts commands appears to have no affect. Unfortunately there appears to be no official documentation on this problem that is helpful, and I am getting conflicting advice from the very few blogs that touch on this subject. If anyone is able to help me sort this out, you can have my firstborn child, or really anything that is mine. I am desperate. I’ve zipped up the fonts, css, xml, and fla if anyone is feeling extra helpful. It is available here:
http://www.danehansen.com/temp/test.zip
Thanks in advance.
#15 by dudule on November 3, 2010 - 6:33 am
On Mac OS X, check for duplicate fonts in Font Book.
#16 by stephen on November 30, 2010 - 3:52 pm
Hi, I too had problems with this and here is how i solved the issue (pure actionscript textfield)
after embedding the font I had to find the correct name
//do this in document class or from frame 1
var fonts:Array = Font.enumerateFonts();
for (var i:int = 0; i < fonts.length; i++)
trace('font – ' +fonts[i].fontName + " – " + fonts[i].fontStyle);
var buttonText:TextField = new TextField();
buttonText.embedFonts = true; //make sure the fonts are embedded
buttonText.defaultTextFormat = new TextFormat(font, 14, 0xFFFFFF, false);//font being the font.fontName of your embedded font
buttonText.text = text; //set the text after embedding & setting format other wise the text disappears!
hope this helps anyone else having issues with doing this at runtime!
#17 by Zoran Ilic on December 8, 2010 - 6:35 pm
Hi to all,
When embedding fonts in Flash CS5 and using AS2 or AS3 be sure to set the player to Flash player 10 in publish settings. I solved my problem with AS2. I didn’t check AS3 but It should be Flash player 10.
Zoran
#18 by AP on December 16, 2010 - 10:34 am
Hi,
#16 by stephen worked for me! After tracing the real font names, and putting that in the CSS font-family part, it worked like a charm.
Thanks,
AP
#19 by michiel on January 18, 2011 - 10:30 am
This works for me in debug mode, but the font is missing when i publish my swf as an air application (it gets replaced by some default font)
#20 by Fabian Irsara on February 2, 2011 - 5:41 pm
As I’ve found a solution that has worked very well for me so far I can really advice you to read my little post about this whole stuff:
http://www.fabian-irsara.com/2011/01/09/embedding-fonts-as3-flash-player-10/
basically you simply add embedAsCFF=”false” and embed the old way, OR you may embed it as you were used to and compiel to flash version 9. I usually export all my needed fonts to different swf-files and load them at runtime to keep filesize small and give a great amount of preloading-feedback!
Hope this might help!
#21 by Arafat on February 8, 2011 - 4:50 am
Hi,
I tried this method. Any idea how to get it working for Combo box component.
Actually the combo box component can show the embedded fonts when it is placed in the main movie clip.
If I load the movieclip-one (which contains the combo box) into another movieclip, the text cannot be shown.
I found similar problems with other developers but I still couldn’t figure it out.
Any help will be appreciated….
Thank you…
#22 by baaknee on March 4, 2011 - 9:56 am
“is there any way I can give my embedded font a unique font-family name to use on my TextFormat?
it’s not actually a problem, but some fonts really have some strange names (eg.Titilium: TitilliumText14L 600 wt, TitilliumText14L Bold, …)”
I believe you can avoid this issue by letting flash deal with the names in the background by using .fontName:
someFormat = new TextFormat(fontLinkageName.fontName, 14, 0×000000);
I could be missing the point though (it happens a lot!)
#23 by Aaron on March 4, 2011 - 10:18 am
baaknee, I think you’re right on with that suggestion for the more complicated font names and as mentioned before, enumerating over the available embedded fonts can help determine whether you’ve got your font embedded and what it’s name actually is.
#24 by Joel on March 18, 2011 - 6:21 pm
I’m running my wife’s site that she purchased from a web development company. There is a Flash object for a Photo Gallery that I used to simply update by modifying an XML file with text and file references to photos I upload to the site.
I recently upgraded to CS5 and I just added some more images and tried to publish. I’m now getting the error:
“Fonts should be embedded for any text that may be edited at runtime, other than text with the “Use Device Fonts” setting. Use the Text > Font Embedding command to embed fonts.”
and it is not publishing the file anymore. I’m not that familiar, yet, with working in Flash. Is there a simple fix for this problem? You probably already gave me the answer above, but unfortunately, most of what you said above doesn’t make a whole lot of sense yet.
I’ll go back and read again.
#25 by Mindy McAdams on April 10, 2011 - 9:46 am
I’m got a loaded XML file feeding text into several differently formatted text fields. Each one has a properly embedded font. Everything is working fine except … BOLD. I have an embedded Verdana Bold font, which I have checked every which way, but the text in the field shows as regular weight.
Using Classic Dynamic Text in Flash CS5 (AS3) on Mac OS.
There is no HTML text, and the text fields are not generated by AS — they are physically on the stage.
Font.registerFont(NumberFont); made no difference.
Any ideas?
#26 by ctmanic on April 14, 2011 - 5:49 pm
Thanks for that, man. Very nice of Adobe to have such a large change and such poor coverage in the documentation. It’s nowhere near as clear as this explanation.
#27 by Nimitt on April 22, 2011 - 6:22 am
Thank u very much buddy.. solved my issue.
#28 by Dane on April 29, 2011 - 12:40 am
you helped me in the past, and i’ve come to another speedbump. i’ve switched to using Flash Builder to write my code in, and i have a project that i was successfully using the [Embed] tags in to get my fonts into the project… after tiring of wresting with gettings the right font names using that, i decided to embed the fonts into a .swc using a more graphical and simpler interface… and it seems to be working. i have a couple of fonts working, but when i wanted to embed 2 weights of Arial then i was not able to get the bold to work. if i embed only bold it will work, and if i embed only regular or both regular AND bold, i only see regular. by tracing out my particular version of arial, i see the fontFamily as “Arial” in both cases but fontStyle is “bold” on one, “regular” on the other. no matter what i stick in my css i cannot get the bold weight to show up once both weights are embedded. i’ve tried “font-weight:bold” and “font-style:bold” and numerous others, but nothing works for me. any ideas? thanks. i can provide source if needed.
#29 by Kate Williams on May 13, 2011 - 12:57 am
Thanks for the article,
So you’re saying rather than needing to create unused dynamic text fields somewhere offstage, you actually embed all the fonts for your project in one place with the new “Font Embedding” dialog?
I’m having trouble with the new cs5 handling of embedding fonts in a textfield that loads xml—any suggestions?
#30 by Chris T. on June 14, 2011 - 2:20 pm
I have a really easy and quick fix for some of you…. Simply un-check “Auto-kern”. Flash seems to want to use device fonts, or won’t display, certain fonts.
Good luck
#31 by Tim LaDuke on June 24, 2011 - 9:07 pm
Leave it to Adobe to have such poor documentation—thankfully we have people like you to help us. I’ll be glad when the days of embedding font are over with the advent of of HTML5. I always struggled with Flash.
#32 by JP DeVries on June 27, 2011 - 8:49 pm
Major drag that Flash CS 5 doesn’t support the embed code! I’m working on a JSFL script that automates the creation of font swfs, and it’s so much simpler to use the [Embed] code.
#33 by Glen on July 29, 2011 - 10:43 am
There is a bit of a “gotcha” with font names when you start using Asian fonts like Gulim, etc.
Flash’s font selection panel very nicely displays the font name in it’s native language, e.g. “Gulim” is not shown, but the Korean equivalent is. The name you need to be using is the system name – it would be good if the panel showed this, but hey that would have saved me hours of work and that’s not Adobe’s job right
#34 by paarth on September 2, 2011 - 4:27 am
Hi,
I am working in flash AS3 – CS5.
what is the code for adding the font dynamically without adding it in the library.
#35 by Stefcot on February 18, 2012 - 2:57 pm
Hi all,
this is the way I use for embedding fonts, of course it’s the same for importing the fonts in the library but after I kept doing the same as in cs3 and cs4 and it works fine :
1. add : import flash.utils.getDefinitionByName; at the top of your class
2. add : Font.registerFont(getDefinitionByName(“YourFontIDInTheLibrary”) as Class);
3. add this to check your font Name :
var embeddedFontsArray:Array = Font.enumerateFonts(true);
for(var i:Number = 0; i < embeddedFontsArray.length; i++) {
trace(embeddedFontsArray[i]);
trace(embeddedFontsArray[i].fontName);
}
That's it guys i hope it will help you