FontManager
| Kind of class: | class |
|---|---|
| Inherits from: | MediaLoad < BytesLoad < RetryableLoad < Load < EventDispatcher < CoreObject |
| Version: | 01/10/07 |
| Author: | Aaron Clinger |
| Classpath: | org.casaframework.load.media.font.FontManager |
| File last modified: | Tuesday, 23 January 2007, 20:42:57 |
Manages dynamic font switching/loading.
To get this working in please follow these steps:
- Create a new FLA file and name it "testFont_lib.fla".
- On the root on testFont_lib.fla create a dynamic textfield.
- Choose a typeface and embed all characters you want to include.
- Enter some text into the textfield.
- Give the textfield an instance name of "font_txt".
- Convert the textfield to a symbol, give it a name of "testFont" and make sure its type is Movie clip.
- Make sure "Export for runtime sharing" is checked under Linkage, and give it an Indentifier of "testFont".
- In the URL field type "testFont_lib.swf". This path is relative to your HTML file, change if necessary.
- Click OK to apply these changes to the symbol.
- Publish this file and save it. You can now close this FLA.
- Create a new FLA and name it "testFont.fla".
- In testFont.fla create a new symbol, give it a name of "testFont" and make sure its type is Movie clip.
- Check "Import for runtime sharing" under Linkage, and give it an Indentifier of "testFont".
- In the URL field type "testFont.swf". This path is relative to your HTML file, change if necessary.
- Under Source click the browse button and find testFont_lib.fla and click open.
- Select source symbol testFont and click OK.
- Click OK to apply these changes to the symbol.
- Make sure the the symbol is on the main stage at the root level and give it an instance name of "fontContainer_mc".
- On a frame at the root place the following code (REQUIRED):
FontManager.registerFont("testFont", this.fontContainer_mc.font_txt, this, true);
- Publish this file and save it. You can now close this FLA.
- 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.
Since:
Flash Player 7
Example:
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); this.fontLoad.start(); function onFontRegister(refrenceName:String, fontTextFormat:TextFormat):Void { FontManager.applyTextFormatByReferenceName(refrenceName, this.headline_txt); this.fontLoad.destroy(); 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 () {} Summary
Class properties
Class properties inherited from BytesLoad
Class properties inherited from RetryableLoad
Class properties inherited from Load
Instance properties
Instance properties inherited from BytesLoad
Instance properties inherited from RetryableLoad
Instance properties inherited from Load
Instance properties inherited from EventDispatcher
Instance properties inherited from CoreObject
Class methods
Instance methods
Instance methods inherited from MediaLoad
Instance methods inherited from BytesLoad
Instance methods inherited from RetryableLoad
Instance methods inherited from Load
Instance methods inherited from EventDispatcher
Instance methods inherited from CoreObject
Class properties
EVENT_FONT_REGISTER
static EVENT_FONT_REGISTER:String = 'onFontRegister'
(read,write)
EVENT_LAST_FONT_REGISTER
static EVENT_LAST_FONT_REGISTER:String = 'onLastFontRegister'
(read,write)
Class methods
applyNewTextFormatByReferenceName
static function applyNewTextFormatByReferenceName (
refrenceName:String,
field_txt:TextField) : Boolean
Assigns a new TextFormat to a TextField and determines if
embedFonts should be true or false.Parameters:
refrenceName:
Reference name of font.
field_txt :
TextField to apply the TextFormat.
Returns:
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.applyTextFormatByReferenceName
static function applyTextFormatByReferenceName (
refrenceName:String,
field_txt:TextField) : Boolean
Assigns a TextFormat to a TextField and determines if
embedFonts should be true or false.Parameters:
refrenceName:
Reference name of font.
field_txt :
TextField to apply the TextFormat.
Returns:
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.getFontReferenceNames
static function getFontReferenceNames (
) : Array
Gets a list of all of the refrence names of registered fonts.
Returns:
Array of font reference names.
getTextFormatByReferenceName
static function getTextFormatByReferenceName (
refrenceName:String) : TextFormat
Looks up and returns a TextFormat by its reference name.
Parameters:
refrenceName:
Reference name of font.
Returns:
A new TextFormat with
font defined.loadFont
static function loadFont (
filePath:String) : FontManager
Load a SWF wrapped font from a external location.
Parameters:
filePath:
The absolute or relative URL of the SWF.
Returns:
FontManager instance.
registerFont
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.
Parameters:
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.isLastRegister:
[optional] Indicates it's the last font registered
true, or that there are other fonts left to register false; defaults to false.Returns:
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
destroy
function destroy (
) : Void
Removes all observers and deletes event functionality. This frees objects for garbage collection.
Always call
Always call
destroy() before deleting/removing event instance.Usage note:
destroy is called automatically after event
onLastFontRegister.