Home > Flash > Runtime Dynamic fonts Flash CS3

Runtime Dynamic fonts Flash CS3

January 28th, 2008

All the examples showing runtime dynamic fonts for flash cs3 includes that you export swf file with a class that contains embedded font [Embed ??my font??].

This doesn’t really works for me because I need specified characters for a lot of different countrys. Usually when developing a flash application I have to handle between 15-50 countrys.

embed01

So I made my own little solution, made one of these for flash 6 for a couple of years ago and the trick still works. It basiclly works by loading shared runtime librarys and then embedded fonts will be shared cross the application when using a lot of swf files.

Making it a static class it’s easy to use.

CSS.loadStyleName = "default";CSS.loadStylePath = "css/";CSS.addEventListener(IOErrorEvent.IO_ERROR, this.onError);CSS.addEventListener(Event.COMPLETE, this.onComplete);CSS.initialize( this );

And then to use it on textfields.

txtField.styleSheet = CSS.styleSheet;txtField.embedFonts = true;txtField.htmlText = "<span class='subTest'>Embed Arial</span>";txtField.rotation = 5;
 
txtField2.styleSheet = CSS.styleSheet;txtField2.embedFonts = true;txtField2.htmlText = "<span class='subTest'>Try embed Arial Black</span>";txtField2.rotation = -5;

To make this work.

1.1) Create your shared library file (example: default_lib.fla)

1.2) Create MovieClip on stage and export it for runtime.

1.3) In the MovieClip create a textfield for each font you need, embedd all the characters needed.
embed02

2.1) Create your shared library holder file (example: default.fla)

2.2) On the stage add the runtime MovieClip and give it instance name mcFont

3.1) Create your css file (example: default.css)

3.2) Add the styles that your need
embed03

4.1) In the Application file add the following load code (look at example in top)

You can download example files here: runtimefonts_as3

Flash , , ,

  1. Han Erim
    December 7th, 2008 at 18:33 | #1

    Your solution is looking nice. Thanks

  2. Han Erim
    December 7th, 2008 at 18:34 | #2

    Exactly it is working. Thank you for your excellent solution. It is solved my all fonts problems in AS3 in FLASH CS3.

  3. Prashant Koshta
    December 7th, 2008 at 18:34 | #3

    Really a nice solution. I work out in this approach every thing is working fine. I work out this approach for other library content also (Like MovieClip).
    Thanks,

  4. Magnus
    December 7th, 2008 at 18:34 | #4

    Lifesaver!

  5. February 11th, 2009 at 08:35 | #5

    Hi,

    Your solution is become a real solution for my application. But I have still a very little problem, may be you can understand the reason. Could you contact with me please. You can see the application on my web site. http://www.flashwebeditor.com. Thanks.

    hanerim@gmail.com

    Han Erim

  6. admin
    February 11th, 2009 at 15:26 | #6

    Hi Han.
    Sorry but the code is for open source use for anyone. Having no problem with you using it in a “buy” application but feels strange to help you out, guessing I’ll not get any % of your profit ;)
    best of luck.

  7. steveb
    March 23rd, 2009 at 16:18 | #7

    Please excuse my ignorance- I am a complete beginner to fonts –

    Does this solution allow this:
    1) I compile and publish a swf application that reads an xml file.
    2) The xml file can be updated as required pointing to new fonts (either on the web as .ttf files, or next best packaged into swf files)
    3) Without re-compliling, my swf application can use those fonts.

    I don’t want to set off down a blind alley, but if it allows the above that would be fantastic. My other option is to do it as an AIR app, and download the fonts to local font folder.

  8. admin
    March 30th, 2009 at 22:42 | #8

    Hi steveb.
    Sorry, there is no way to runtime compile the fonts and characters that you need. But you can setup font-package swf files that are ready. I’m not quite sure either that an AIR application can use runtime ttf fonts either.
    For e.g. I create a lot of international flash applications (that’s why my big interest in dynamic fonts). So my sites can load text xml files and as well witch font package (witch I control with CSS files).
    That means for e.g. when I publish my site for European western-latin I can then switch (loading/runtime) to Cyrillic/Russian or why not Cantonese/Chinese without any problems.

  9. Philippe
    May 19th, 2009 at 06:58 | #9

    Very nice solution. It is working well for regular fonts, but I am having trouble to embed bold and/or italic fonts.
    What do you suggest to do?
    Thanks

  10. admin
    June 8th, 2009 at 15:22 | #10

    Embed bold and italic in the FLA file, remember if you want a bold + italic you need to embed that as well. Each different embedded kerning in Flash is handled as a own “font set” (note that the file size increases).

    After having a textfield and embedding the font, make sure to use e.g. bold in the CSS file. Example:
    h1
    {
    font-family: Verdana;
    font-size: 12px;
    font-weight:bold;
    }

    A tip here is to check out the supported Flash CSS types. You can e.g. add a couple of more values.
    h1
    {
    font-family: Verdana;
    font-size: 12px;
    font-weight:bold;
    color: #746e57;
    leading:-1px;
    }

  1. February 13th, 2009 at 14:35 | #1