Are you specifying the range of glyphs properly for the fonts? a-z, numbers, punctuation, etc but more to the point any special characters you might need in extended character sets like latin, greek, etc. Make sure you have those embedded.
The immediate reason that comes to mind why it works when you embed it directly is Flash might see a TextField utilizing a glyph that has not been marked to embed, so Flash helped you by adding that character to the embed. When blindly embedding fonts in a separate SWF it won't help you with that.
Also Flash uses the systems codepage to limit the glyphs internally. This can be overridden in other apps like Flash Builder but in Flash Pro you're at the mercy of the system codepage as far as what gets embedded. What this means is even though you embed "Arial" and check off to embed "[x] All" glyphs, it still won't do it. Arial definitely contains many other languages glyphs but Flash will refuse to embed them for OS fonts. If your font is special/custom this probably isn't the case as Flash tends to obey in that situation.
Worst case scenario for you is you may need to put a TextField containing the missing characters in the font SWF. Put it on stage so Flash will embed the glyphs. If you're wholesale missing basic characters like letters, that's a different story.
I have noticed that the only characters that do display are the ones that are in the textfield at design time. It's like Flash is treating the textfield as if the font is not embedded (because it's not embedded in that fla file), although it is loaded from an external swf and should work. Actually it DOES work for the characters that it decides to display. I have verified that if I publish the font swf without the font, then the font in the textfield reverts to a system font, so I know the textfield is trying to use the externally loaded font.
Are you loading your external fonts into your applications current domain context?
// not adding error checking but you should have it
var ldrContext:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain,null);
var fontLoader:Loader = new Loader();
fontLoader.load(new URLRequest('fonts.swf'), ldrContext);
You should make sure your fonts are available to your applicationDomain. Check to see if it loaded your fonts via their exported class definition:
// hopefully traces true:
Depends on the type of project however.
It's not an application domain issue, I know that's good.
However, going off an idea you gave me in your previous response, I decided to create some dummy textfields in the swf that has the textfields, where these dummy textfields contain every character I want to use from the font. Then I made a movieclip out of all of those textfields and set it to invisible. Republish, run, and there are all the characters.
So like I mentioned above, it seems like Flash is doing something during the publish where it only recognizes characters that are in textfields at design time, even if the full font is available from an external swf at runtime. Again, I think this is a Flash bug, but hardly expect Adobe to acknowledge it.
Thanks for the replies!
It's the codepage issue at work again. If you have Flash Builder you can force unicode ranges into the embedded fonts.
BTW are you importing the font into your library or are you using [Embed] tags on an external font? Try your luck at embedding it in your class for the document, e.g.
[Embed(source='SomeFont.ttf', fontName="SomeFont", mimeType="application/x-font-truetype", advancedAntiAliasing="true", embedAsCFF="false")];
private static var SF:String;
That'll instruct the compiler to embed it. You may have more luck with this.
I'm embedding using the font embedding UI in Flash Pro. But I know that the characters are all embedded, based on the swf file size, which varies if I remove some characters from the embedding. I haven't tried the Embed tag, mainly because I was avoiding making a script if I didn't need it.
For S&G I decided to try the Embed tag. Once I got the embedding working that way, I witnessed the exact same issue. The characters were missing until I added a textfield in the display swf that includes all the characters from the font. So I guess I have confirmed that it's not the embedding process that is going bad.
It's a pretty well known issue that Flash internally makes some decisions it shouldn't when embedding. Why it does is pretty magical to me. I've fought the issue mostly in AS2 projects for almost a decade. It continues to this day..
At any rate, glad you got your project working which is all that matters to a deadline .
If you're all set please mark helpful/correct so we can filter unanswered. Good luck!
It turns out that there does appear to be some secret embedding going on, of the characters that are in textfields at design time. I added textfields that contain the full character set of the fonts that I am loading externally, to force the characters to appear properly, and BAM, the swf size goes up just as much as if I embedded those fonts. This is so annoying.
Please do yourself a huge favor and consider time=money. I wish it "just worked" but Flash Builders ability to specify unicode ranges lets you embed exactly what you want without the codepage selectivity. Otherwise at least you have a workaround.
I'm not sure what you mean about the codepage selectivity.
I think I have finally found the source of this bug, and it's extremely bizarre. First, a little background on how our project was set up before I started on this path...
We have one main swf that contains all of our code. We have many swf's that are purely UI stuff. Every UI swf has fonts embedded, redundantly.
In an effort to eliminate the redundant font embedding, I started on this task to make a swf purely for embedded fonts, and to remove the embedded fonts from all the UI swf's, which led me to the issue of missing characters.
Now I have found out that if I go into the UI swf's and set the fonts to something else like _sans, then set it back and republish, then all of the characters in that textfield appear properly as expected. It's like there's some old font embedding information stuck in the textfields from previously having the embedding in that file.
This is why I take a 98% code approach to all projects. My TextFields are all formatted using the TextFormat class. I embed or load a SWC with fonts in the main project and have anything else loaded use the fonts I loaded one time into the main app.
Consider there's also Runtime Shared as an option for you. That's where you mark all your fonts in a Font.FLA for export as runtime shared. Then simply create the same fonts in your other UI parts but set them to import from the runtime shared file. Then you can work on the separate UI components while still seeing the correct font.
System codepage just means if I'm on a copy of Windows English then that will be the language Flash considers most important. If I try to embed Arial and then programmatically create and populate a TextField with Chinese, it won't work, nothing will show up. Even if I explicitly tell Flash to include the Chinese glyphs (of which definitely exist in Arial). Becuase I can't specify the unicode range I need and force it like Flash Builder, Flash "magically internally" would decide all I need is English (latin) glyphs and would not embed the Chinese glyphs. That magical behavior was always a pain.