This topic has always been a focus on how to embed fonts in flash applications.
Most simply, turn on flash, create a new dynamic text, select a font, and then select or add the characters you want to embed in the Embed characters.
More complex are the following two embedding methods for Flex and action script items in Flash Builder.
Flex Project
Using the CSS format swf file:
The CSS file defines the following example
- @font-face{
- Src:url ("Xxx.ttf");
- font-family:xxx;
- Unicoderange:
- U+0041-U+005A,/* upper-case [A ...] Z] */
- u+0061-u+007a, * lower-case A-Z *
- u+0030-u+0039/* Numbers [0..9] * *,
- .....}
Then use MXMLC to publish CSS as a SWF file, using stylemanager.loadstyledeclarations ([url]) to invoke, after the successful call can get font information.
Flash items
Using the Embed label
- [Embed (source= "Xxx.ttf", fontfamily= "xxx", unicoderange= "...")]
- private Var Myfontclass:class;
- ...
- Font.registerfont (Myfontclass)
Copy Code
The advantage of the previous method is that it loads the font information at run time, but, as with the latter method, the disadvantage is that using unicoderange does not make it much better to edit the characters you want to embed. Let me focus on the way I most Advocate runtime loading fonts:
1, create font library Flash files (such as FONT_LIB.FLA), use the simplest method, open flash, create text on the stage, and manually add character sets.
2, establish an as as a application, such as the font_zh.as core code as follows:
- [Embed (source= "font_lib.swf", fontname= "xxxx")]
- private Var Fontclass:class;
- Note that the font name XXX should match the font name used in the text in Font_lib.fla.
- ....
- Font.registerfont (Fontclass)
3, create CSS files, such as Style.css:
- headline{
- font-family: ' xxx '
- Font-size:20
- }
4, runtime load Style.css, initialize with stylesheet:
- var tmpstylesheet:stylesheet = new StyleSheet ();
- TMPSTYLESHEET.PARSECSS (the content of the parameter is CSS);
5, after loading the font_zh.swf, you can use the font, such as:
- var Tf:textfield = new TextField ();
- Tf.stylesheet = Tmpstylesheet;
- Tf.embedfonts = true;
- Tf.htmltext = "
Such a method, a lot of benefits, both can load the font file runtime, but also easy to modify the need to embed the characters.
The only problem that is always unavoidable is that you cannot define an embedded character when you are unable to run it, and you cannot avoid having to manually update the font character every time you modify it.