FontManager
Kind of class: | class |
---|---|
Inherits from: | MediaLoad < BytesLoad < RetryableLoad < Load < EventDispatcher < CoreObject |
Version: | 03/21/08 |
Author: | Aaron Clinger |
Classpath: | org.casalib.load.media.font.FontManager |
File last modified: | Monday, 01 December 2008, 13:34:40 |
Manages dynamic font switching/loading.
To create an externally loadable Font resource please use the following steps:
To create an externally loadable Font resource please use the following steps:
- Create a new FLA file and name it yourFontDesc_lib.fla.
- On the root of yourFontDesc_lib.fla create a dynamic TextField.
- Choose a typeface and embed all characters you want to include. Include "Basic Latin" for this example.
- Enter some text into the TextField. This is required to have the font successfully register. It is recommend to enter the font name into the field.
- Give the TextField an instance name of font_txt.
- Convert the TextField to a symbol, give it a name of myFont, and make sure its type is MovieClip.
- Make sure "Export for runtime sharing" is checked under Linkage, and give it an Indentifier of myFont.
- In the URL field type [yourFontDesc_lib].swf. This path is relative to the HTML file that your shell SWF will be loaded into, so change the path in this URL field 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 yourFontDesc.fla.
- In yourFontDesc.fla create a new symbol, give it a name of myFontContainer, and make sure its type is MovieClip.
- Check "Import for runtime sharing" under Linkage, and give it an Indentifier of myFontContainer.
- In the URL field type the same URL you used in the [yourFontDec_lib].fla URL field (Univers_55_lib.swf in the screenshot below). It actually doesn't matter what you type here, because it will automatically update with the correct value (even if it gives you an error) once you complete the next few steps.
- Under Source click the browse button and find yourFontDesc_lib.fla and click Open.
- Select source symbol myFont 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):
import org.casalib.load.media.font.FontManager; FontManager.registerFont("myFontReferenceName", this.fontContainer_mc.font_txt, this, true);
Please note: If you are concerned about the extra file size added by the FontManager class, you can compile against an intrinsic class for your external font SWFs. - Publish this file and save it. You can now close this FLA.
- Now you can 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(referenceName:String, fontTextFormat:TextFormat):Void { FontManager.applyTextFormatByReferenceName(referenceName, this.headline_txt); this.fontLoad.destroy(); delete this.fontLoad; }
Events broadcasted to listeners:
onFontRegister = function (referenceName:String, fontTextFormat:TextFormat) {}
onLastFontRegister = function (sender:FontManager) {}
Summary
Class properties
- EVENT_FONT_REGISTER : String
- EVENT_LAST_FONT_REGISTER : String
Class properties inherited from BytesLoad
Class properties inherited from RetryableLoad
Class properties inherited from Load
Class methods
- loadFont (filePath:String) : FontManager
- Load a SWF wrapped font from a external location.
- getTextFormatByReferenceName (referenceName:String) : TextFormat
- Looks up and returns a TextFormat by its reference name.
- applyTextFormatByReferenceName (referenceName:String, field_txt:Object) : Boolean
- Assigns a TextFormat to a TextField and determines if embedFonts should be true or false.
- applyNewTextFormatByReferenceName (referenceName:String, field_txt:Object) : Boolean
- Assigns a new TextFormat to a TextField and determines if embedFonts should be true or false.
- getFontReferenceNames : Array
- Gets a list of all of the refrence names of registered fonts.
- registerFont (referenceName:String, field:Object, sender_mc:MovieClip, isLastRegister:Boolean) : Boolean
- Used by external font SWF files to register fonts.
Instance methods
- destroy : Void
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 (
referenceName:String,
field_txt:Object) : Boolean
Assigns a new TextFormat to a TextField and determines if
embedFonts
should be true
or false
. Parameters:
referenceName:
Reference name of font.
field_txt :
TextField or org.casalib.textfield.CoreTextField to apply the TextFormat.
Returns:
- Returns
true
if TextFormat byreferenceName
was successfully found; otherwisefalse
.
Usage note:
- Automatically sets
embedFonts
totrue
iffont
is NOT_sans
,_serif
or_typewriter
; otherwise setsembedFonts
tofalse
.
applyTextFormatByReferenceName
static function applyTextFormatByReferenceName (
referenceName:String,
field_txt:Object) : Boolean
Assigns a TextFormat to a TextField and determines if
embedFonts
should be true
or false
. Parameters:
referenceName:
Reference name of font.
field_txt :
TextField or org.casalib.textfield.CoreTextField to apply the TextFormat.
Returns:
- Returns
true
if TextFormat byreferenceName
was successfully found; otherwisefalse
.
Usage note:
- Automatically sets
embedFonts
totrue
iffont
is NOT_sans
,_serif
or_typewriter
; otherwise setsembedFonts
tofalse
.
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 (
referenceName:String) : TextFormat
Looks up and returns a TextFormat by its reference name.
Parameters:
referenceName:
Reference name of font.
Returns:
- A new TextFormat with
font
defined.
loadFont
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:Object,
sender_mc:MovieClip,
isLastRegister:Boolean) : Boolean
Used by external font SWF files to register fonts. Should not be called by anything else.
Parameters:
referenceName :
The unique reference name of your font. Used to look up at a later time with getTextFormatByReferenceName.
field :
TextField or org.casalib.textfield.CoreTextField 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 parametersender_mc
was referenced correctly and the font was successfully registered; otherwisefalse
.
Usage note:
- Parameter
isLastRegister
should only betrue
during the registering of the last font in the loaded SWF. If there is only one font being registered it should always betrue
.
Instance methods
destroy
function destroy (
) : Void
Usage note:
-
destroy
is called automatically after eventonLastFontRegister
.
Overrides: