Edited Short Version:
The Adobe Flash docs list a property embedFonts
on TextAreas:
A Boolean value that indicates whether the font specified in fontFamily is an embedded font. This style must be set to true if fontFamily refers to an embedded font. Otherwise, the embedded font is not used. If this style is set to true and fontFamily does not refer to an embedded font, no text is displayed. The default value is false.
Regarding the "If this style is set to true and fontFamily does not refer to an embedded font, no text is displayed" statement: How can I detect in ActionScript when this scenario happens?
TL;DR Original Version:
I have a flash application which loads external .swf
files containing embedded fonts, so that these fonts can be used within the main application. We're accomplishing this by using the following ActionScript code on anything which uses custom fonts:
textBoxName.embedFonts = true;
However, sometimes the requested font is not available in the external .swf
file which is loaded -- this often happens when someone makes changes to the external .swf
and doesn't include all the fonts which were previously in there...
The reason is not important, what's important is that it's unavoidable and will happen. When it does, any text in a font that's not available does not display at all. For example:
- Main application is set up to use "Myriad". It's loading an external
swf
file which does contain Myriad along with a handful of other fonts - Some time later, the external
swf
is updates to contain a new set of fonts, and Myriad is no longer one of them. But the main application is not updated. - Now, all text in the main application that was in "Myriad" no longer displays at all.
Is there any way to either default the text to a font that is available, or, detect that the font is not available and run some ActionScript code?
EDIT: In case it matters, here's the code I'm using to load the fonts from the external swf
files:
// Font Loader:
var loadedFonts = Array();
var fontPakLoadHandler = new Object();
fontPakLoadHandler.percent = 0;
fontPakLoadHandler.onLoadStart = function(target_mc:MovieClip)
{
if(!SuspendEvents)
ExternalInterface.call("fontLoadStart", _root.lcId);
}
fontPakLoadHandler.onLoadInit = function(target_mc:MovieClip)
{
if(!SuspendEvents)
ExternalInterface.call("fontLoadInit", _root.lcId);
}
fontPakLoadHandler.onLoadError = function(target_mc:MovieClip, errorCode:String, httpStatus:Number)
{
if(!SuspendEvents)
ExternalInterface.call("fontLoadError", _root.lcId, errorCode, httpStatus);
}
if(_root.fontPakProgress=='all')
{
fontPakLoadHandler.onLoadProgress = function(target_mc:MovieClip, loadedBytes:Number, totalBytes:Number)
{
fontPakLoadHandler.percent = loadedBytes / totalBytes;
if(!SuspendEvents)
ExternalInterface.call("fontLoadProgress", _root.lcId, loadedBytes, totalBytes, fontPakLoadHandler.percent);
}
}
else
{
fontPakLoadHandler.onLoadProgress = function(target_mc:MovieClip, loadedBytes:Number, totalBytes:Number)
{
var perc = loadedBytes / totalBytes;
if( (fontPakLoadHandler.percent < .75 && perc >= .75) ||
(fontPakLoadHandler.percent < .50 && perc >= .50) ||
(fontPakLoadHandler.percent < .25 && perc >= .25))
{
if(!SuspendEvents)
ExternalInterface.call("fontLoadProgress", _root.lcId, loadedBytes, totalBytes, perc);
}
fontPakLoadHandler.percent = perc;
}
}
fontPakLoadHandler.onLoadComplete = function(target_mc:MovieClip, httpStatus:Number)
{
if(!SuspendEvents)
ExternalInterface.call("flashReady", _root.lcId, true);
//ExternalInterface.call("fontLoadComplete", _root.lcId, httpStatus);
}
var fontPakLoader = new MovieClipLoader();
fontPakLoader.addListener(fontPakLoadHandler);