套件 | mx.core |
類別 | public class FontAsset |
繼承 | FontAsset Font Object |
實作 | IFlexAsset |
語言版本: | ActionScript 3.0 |
產品版本: | Flex 3 |
執行階段版本: | Flash Player 9, AIR 1.1 |
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"/>
更多範例
相關 API 元素
方法 | 定義自 | ||
---|---|---|---|
Constructor. | FontAsset | ||
[靜態]
會指定是否要提供目前可用嵌入字體的清單。 | Font | ||
會指定提供的字串是否可以使用目前指派的字體顯示。 | Font | ||
指出物件是否有已定義的指定屬性。 | Object | ||
指出 Object 類別的實體是否位於指定為參數的物件原型鏈中。 | Object | ||
指出指定的屬性是否存在,以及是否可列舉。 | Object | ||
[靜態]
會在全域字體清單中註冊字體類別。 | Font | ||
為迴圈作業設定動態屬性的可用性。 | Object | ||
傳回代表此物件的字串,根據地區特定慣例進行格式化。 | Object | ||
會傳回指定之物件的字串形式。 | Object | ||
會傳回指定之物件的基本值。 | Object |
FontAsset | () | 建構函式 |
public function FontAsset()
語言版本: | ActionScript 3.0 |
產品版本: | Flex 3 |
執行階段版本: | Flash Player 9, AIR 1.1 |
Constructor.
Tue Jun 12 2018, 03:47 PM Z