The advanced method of flash embedded fonts

Source: Internet
Author: User

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

    1. @font-face{
    2. Src:url ("Xxx.ttf");
    3. font-family:xxx;
    4. Unicoderange:
    5. U+0041-U+005A,/* upper-case [A ...] Z] */
    6. u+0061-u+007a, * lower-case A-Z *
    7. u+0030-u+0039/* Numbers [0..9] * *,
    8. .....}

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

    1. [Embed (source= "Xxx.ttf", fontfamily= "xxx", unicoderange= "...")]
    2. private Var Myfontclass:class;
    3. ...
    4. 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:

    1. [Embed (source= "font_lib.swf", fontname= "xxxx")]
    2. private Var Fontclass:class;
    3. Note that the font name XXX should match the font name used in the text in Font_lib.fla.
    4. ....
    5. Font.registerfont (Fontclass)


3, create CSS files, such as Style.css:

    1. headline{
    2. font-family: ' xxx '
    3. Font-size:20
    4. }


4, runtime load Style.css, initialize with stylesheet:

    1. var tmpstylesheet:stylesheet = new StyleSheet ();
    2. TMPSTYLESHEET.PARSECSS (the content of the parameter is CSS);


5, after loading the font_zh.swf, you can use the font, such as:

    1. var Tf:textfield = new TextField ();
    2. Tf.stylesheet = Tmpstylesheet;
    3. Tf.embedfonts = true;
    4. 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.