1
votes

I'm using Flash CS5 and I have a problem with my exported SWF file: it's over 100kb in size. I have 2 vectorial symbols and 4 dynamic text with embed Calibri font boxes which are displaying information from an external XML file. These text boxes are the ones which are generating the most size of my swf file. I need to cut down somewhere, I've searched but I haven't came across a "best practices guide to embedding fonts in a flash file". I find it hard to believe that if you only embed alphanumerical characters of 1 single font your file size reaches >100kb..

1

1 Answers

2
votes

I've been in your shoes a few times and ultimately established an ant build system for fonts to swfs and swcs using compc and mxmlc. A quick test with Calibri Regular, punctuation, alpha, and numeric, lead to a swc size of ~22KB. I'm unsure what CS5 is doing to blow out the swf size.

My recommendation would be to generate the font swc with compc, then link the library to your project, and overwrite the text field's existing text formats with one that specifies for the linked font file.

This is the class I used to generate the swc/swf:

package
{

import flash.display.Sprite;

public class Calibri extends Sprite
{
    [Embed(source="../assets/calibri.ttf", fontName="Calibri", mimeType="application/x-font", unicodeRange='U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E')]
    public static var fontClass:Class;
    public static var fontName:String = "Calibri";
}

}

Useage of the linked font library:

Font.registerFont(Calibri.fontClass);

Reference for TextFormat objects:

textFormat.font = Calibri.fontName;

Best of luck!