ActionScript® 3.0 Reference for the Adobe® Flash® Platform
Home  |  Show Packages and Classes List |  Packages  |  Classes  |  What's New  |  Index  |  Appendixes
mx.core 

FontAsset  - AS3 Flex

Packagemx.core
Classpublic class FontAsset
InheritanceFontAsset Inheritance Font Inheritance Object
Implements IFlexAsset

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

FontAsset is a subclass of the flash.text.Font class which represents fonts that you embed in a Flex application.

The font that you embed can be TrueType (TTF) or OpenType (OTF). You can also embed a system font or a font that is in a SWF file produced by Flash. In each of these cases, the MXML compiler autogenerates a class that extends FontAsset to represent the embedded font.

You do not generally use the FontAsset class directly when you write a Flex application. For example, you can embed a font by using the font-face CSS selector without having to understand that the MXML compiler has created a subclass of FontAsset for you.

However, it might be useful to understand what is happening at the ActionScript level. To embed a font in ActionScript, you declare a variable of type Class, and put [Embed] metadata on it. For example, you embed a TTF file like this:

  [Embed(source="Fancy.ttf", fontName="Fancy")] 
  var fancyClass:Class;
  

The MXML compiler transcodes the TTF data into the font format that the player uses, autogenerates a subclass of the FontAsset class, and sets your variable to be a reference to this autogenerated class. You can then use this class reference to create instances of the FontAsset by using the new operator, and you can use APIs of the Font class on them; for example:

  var fancyFont:FontAsset = FontAsset(new fancyClass());
  var hasDigits:Boolean = fancyFont.hasGlyphs("0123456789");
  

However, you rarely need to create FontAsset instances yourself because you use the fontName that you specify in the [Embed] metadata to refer to the font; for example, you set the fontFamily CSS style to the font name (in this example, "Fancy"), and not to a FontAsset instance such as fancyFont or to the fancyClass class reference. For example:

  <mx:Label text="Thank you for your order." fontFamily="Fancy"/>
  

More examples

Learn more

Related API Elements



Public Properties
 PropertyDefined By
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
 InheritedfontName : String
[read-only] The name of an embedded font.
Font
 InheritedfontStyle : String
[read-only] The style of the font.
Font
 InheritedfontType : String
[read-only] The type of the font.
Font
Public Methods
 MethodDefined By
  
Constructor.
FontAsset
 Inherited
enumerateFonts(enumerateDeviceFonts:Boolean = false):Array
[static] Specifies whether to provide a list of the currently available embedded fonts.
Font
 Inherited
Specifies whether a provided string can be displayed using the currently assigned font.
Font
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
[static] Registers a font class in the global font list.
Font
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Constructor Detail

FontAsset

()Constructor
public function FontAsset()

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Constructor.