Access keys


Kind of class: class
Inherits from: MediaLoad < BytesLoad < RetryableLoad < Load < EventDispatcher < CoreObject
Version: 12/20/06
Author: Aaron Clinger
File last modified: Monday, 08 January 2007, 09:57:51
Manages dynamic font switching/loading.

To get this working in please follow these steps:
  1. Create a new FLA file and name it "testFont_lib.fla".
  2. On the root on testFont_lib.fla create a dynamic textfield.
  3. Choose a typeface and embed all characters you want to include.
  4. Enter some text into the textfield.
  5. Give the textfield an instance name of "font_txt".
  6. Convert the textfield to a symbol, give it a name of "testFont" and make sure its type is Movie clip.
  7. Make sure "Export for runtime sharing" is checked under Linkage, and give it an Indentifier of "testFont".
  8. In the URL field type "testFont_lib.swf". This path is relative to your HTML file, change if necessary.
  9. Click OK to apply these changes to the symbol.
  10. Publish this file and save it. You can now close this FLA.
  11. Create a new FLA and name it "testFont.fla".
  12. In testFont.fla create a new symbol, give it a name of "testFont" and make sure its type is Movie clip.
  13. Check "Import for runtime sharing" under Linkage, and give it an Indentifier of "testFont".
  14. In the URL field type "testFont.swf". This path is relative to your HTML file, change if necessary.
  15. Under Source click the browse button and find testFont_lib.fla and click open.
  16. Select source symbol testFont and click OK.
  17. Click OK to apply these changes to the symbol.
  18. Make sure the the symbol is on the main stage at the root level and give it an instance name of "fontContainer_mc".
  19. On a frame at the root place the following code (REQUIRED):
    FontManager.registerFont("testFont", this.fontContainer_mc.font_txt, this, true);
  20. Publish this file and save it. You can now close this FLA.
  21. Now follow and use the code in the example below to load and apply the font. Follow these steps for each font you would like to load.
Flash Player 7
this.createTextField("headline_txt", this.getNextHighestDepth(), 50, 50, 300, 100);
this.headline_txt.border = this.headline_txt.background = this.headline_txt.wordWrap = this.headline_txt.multiline = true;
this.headline_txt.type = "input";
this.headline_txt.text = "This is an example of dynamic font loading with FontManager.";

var fontLoad:FontManager = FontManager.loadFont("testFont.swf");
this.fontLoad.addEventObserver(this, FontManager.EVENT_FONT_REGISTER);

function onFontRegister(refrenceName:String, fontTextFormat:TextFormat):Void {
    FontManager.applyTextFormatByReferenceName(refrenceName, this.headline_txt);

    delete this.fontLoad;
Events broadcast to listeners:
onLoadStart = function (sender:Object) {}
onLoadStop = function (sender:Object) {}
onLoadError = function (sender:Object) {}
onFontRegister = function (referenceName:String, fontTextFormat:TextFormat) {}
onLastFontRegister = function () {}


Instance properties
Instance properties inherited from MediaLoad
Instance properties inherited from RetryableLoad
Instance properties inherited from Load
Instance properties inherited from EventDispatcher
Instance properties inherited from CoreObject

Class properties


static EVENT_FONT_REGISTER:String = 'onFontRegister'


static EVENT_LAST_FONT_REGISTER:String = 'onLastFontRegister'

Class methods


static function applyTextFormatByReferenceName (
refrenceName:String, field_txt:TextField) : Boolean
Assigns a TextFormat to a TextField and determines if embedFonts should be true or false.
Reference name of font.
field_txt :
TextField to apply the TextFormat.
Returns true if TextFormat by refrenceName was successfully found; otherwise false.
Usage note:
Automatically sets embedFonts to true if font is NOT _sans, _serif or _typewriter; otherwise sets embedFonts to false.


static function getFontReferenceNames (
) : Array
Gets a list of all of the refrence names of registered fonts.
Array of font reference names.


static function getTextFormatByReferenceName (
refrenceName:String) : TextFormat
Looks up and returns a TextFormat by its reference name.
Reference name of font.
A new TextFormat with font defined.


static function loadFont (
filePath:String) : FontManager
Load a SWF wrapped font from a external location.
The absolute or relative URL of the SWF.
FontManager instance.


static function registerFont (
referenceName:String, field:TextField, sender_mc:MovieClip, isLastRegister:Boolean) : Boolean
Used by external font SWF files to register fonts. Should not be called by anything else.
refrenceName :
The unique reference name of your font. Used to look up at a later time with getTextFormatByReferenceName.
field :
TextField with the embedded font.
sender_mc :
Reference to the external SWFs root/shell; if this code is on the top timeline sender_mc should be this.
[optional] Indicates it's the last font registered true, or that there are other fonts left to register false; defaults to false.
Returns true if parameter sender_mc was referenced correctly and the font was successfully registered; otherwise false.
Usage note:
Parameter isLastRegister should only be true during the registering of the last font in the loaded SWF. If there is only one font being registered it should always be true.

Instance methods


function destroy (
) : Void
Removes all observers and deletes event functionality. This frees objects for garbage collection.

Always call destroy() before deleting/removing event instance.
Usage note:
destroy is called automatically after event onLastFontRegister.