The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 13 of 13

Thread: Embedding adds 150kb to the SWF! Unacceptable!

Hybrid View

  1. #1

    Embedding adds 150kb to the SWF! Unacceptable!

    Due to my need to tween TextFields, Flash managed to botch up simple scale Tweening (per my previous post), so now I am desperate.

    Right now, the font is embedded, and it's doubling the total SWF size.

    I want to be able to tween the size of the TextFields, without that "jerky" motion. Some way to convert it to vector graphics would likely be the best option.

    I tried rendering as a bitmap, but it isn't getting the desired result, and the hit areas of the TextFields seem way off. Also, it tends to blur quite a bit, even though the scale is only 1.2.

    If anyone can devise a good workaround, I will forever be grateful, and when I get paid for this project, I will paypal $20 to whoever finds the solution.

    < Four hours of sleep last night getting this half crappy project done, and Adobe kills me with something I can't control.
    Blog article of the month: Why My One Line 'if' Statements Are Unusual
    Twitter: @IQAndreas
    GitHub: IQAndreas

  2. #2
    Holosuite User
    Would systemFont make it any different in terms of size?

    I support FlashDevelop (the .NET open source editor for Flash and web developers)
    couchsurfing if you need it

  3. #3
    Quote Originally Posted by wvxvw View Post
    Would systemFont make it any different in terms of size?
    Ooh. Will that take the font from the user's system fonts, or will it still embed it from the font file I have on my computer?

    I am using plain old Arial and ArialNarrowBold. That's all.
    Blog article of the month: Why My One Line 'if' Statements Are Unusual
    Twitter: @IQAndreas
    GitHub: IQAndreas

  4. #4
    Hm... Funny. It bumped up my SWF size from 303KB to 368KB...

    Yet it still warned me that fonts might show up differently on the client machine, so I'm not sure why in the world it's still so large. (that's what she said)

    Here is the code I'm using if it makes any difference (It's all static and located in one "factoryish" class.
            [Embed(systemFont="Arial", fontName="ArialBold", fontWeight= "bold", mimeType="application/x-font")]
            private static var ARIAL_NARROW_BOLD:String;
            private static var _questionTextFormat:TextFormat;
            public static function get questionTextFormat():TextFormat
                if (_questionTextFormat)
                    { return _questionTextFormat; }
                    _questionTextFormat = new TextFormat();
                    //_textFormat.font = "Times New Roman"; //DEFAULT
                    _questionTextFormat.font = "ArialBold";
                    _questionTextFormat.size = 14;
                    //_questionTextFormat.bold = true;
                return _questionTextFormat;
            public static function makeQuestionTF(questionTF:TextField):TextField
                if (questionTF == null)
                { return questionTF; }
                questionTF.selectable = false;
                questionTF.multiline = true;
                questionTF.defaultTextFormat = PublicSettings.questionTextFormat;
                //These two are required in order to tween properly.
                questionTF.embedFonts = true;
                questionTF.antiAliasType = AntiAliasType.ADVANCED;
                questionTF.wordWrap = true;
                questionTF.autoSize = TextFieldAutoSize.LEFT;
                //Make modifications to the existing textField AND return the instance
                return questionTF;

    Last edited by IQAndreas; November 29th, 2009 at 07:56 AM.
    Blog article of the month: Why My One Line 'if' Statements Are Unusual
    Twitter: @IQAndreas
    GitHub: IQAndreas

  5. #5
    Registered User
    have you embedded the whole font of just some characters?

  6. #6
    Quote Originally Posted by lope View Post
    have you embedded the whole font of just some characters?
    The entire font. I'm using code and not the IDE.

    Also, there are a few non-A-Z characters, including punctuation and several european characters, including Swedish, Danish, and a few Spanish (with the tilde), but it definitely doesn't use chinese or japanese symbols. Are those included by default and can be removed via code, or do I have to recreate my own font in order to exclude them?
    Blog article of the month: Why My One Line 'if' Statements Are Unusual
    Twitter: @IQAndreas
    GitHub: IQAndreas

  7. #7
    What's unacceptable about it?

    Using Flash is always going to be a trade-off between the minimum possible SWF size, and the maximum possible number of assets. In that respect, using fonts is no different to adding sound or images to an SWF. If you want to include fonts that might not be installed on the client's PC, then you must include them in your SWF, particularly if you intend to do any dynamic resizing or rendering of the text.

    However that doesn't mean that you have to embed every character outline in the font because, contrary to what you think, you actually have a lot of control over how you use your fonts.

    If your text is going to remain the same, you can use a static textfield. Flash will automatically embed just the characters you are using.

    The real problems start when you're attempting to use dynamic text. Flash isn't clairvoyant and it can't second-guess what characters you intend to use so you have two options. You can use the embed button in the Text Properties to enter just the characters you will be using and Flash will only add these to your SWF, increasing your SWF filesize each time you add a character. Or you can play safe and embed the entire font to your SWF but this will increase the SWF filesize dramatically.

    There are also other alternatives you could use, such as creating a shared library containing your font outlines. You can then import them from this library in much the same way as you'd import an mp3 file or a jpg.
    2006-11 GlosRFC - Searching 8,168,684,336 brain cells

  8. #8
    Quote Originally Posted by glosrfc View Post
    What's unacceptable about it?
    I love that font can be embedded. That's wonderful! I can choose any unusual or odd font out there, and use if for my projects to my hearts content, I don't care about the size then!

    The unacceptable part is that it's Arial. Plain old Arial, which 99.99% of all operating systems have. And if it doesn't have it, fine, use something else, use Times New Roman for all I care.

    All I want is Flash to take that system font, whatever it's choice, and treat it as a vector image, meaning, when I scale it up, it will grow smoothly. I don't want to rerender it at different font sizes, and I really don't want to embed fonts that every Tom, ****, and Stanley already have, especially when I'm pressed for space as it is. Is that really so hard? (that's what she said) If I understand correctly, fonts are basically already are vector images, and depending on what size you pass in, it will output a differently scaled and proportioned vector image.

    Sadly, my TextFields all have to be dynamic, and created dynamically (via code), so they can't be broken apart or crated in the IDE.
    Blog article of the month: Why My One Line 'if' Statements Are Unusual
    Twitter: @IQAndreas
    GitHub: IQAndreas

  9. #9
    As I said in the previous thread, your end user will probably care if they're one of those people that don't have Arial or Times New Roman installed.

    Fonts are not vector images at all - they are mathematical representations of the lines and curves necessary to draw the font plus something else called hinting. When Flash, or any other program, attempts to draw a font, it doesn't simply scale a vector image. It has to calculate, and then render the final image on the fly, much the same way as you would if you were using the lineTo and curveTo functions in Flash.

    At smaller sizes, font outlines can become unreadable and so the rendering uses the shape hinting that is included within the font, rather than the line and curve data. Note that this is a particular problem with fonts that have been deliberately designed for readability. The more readable the font (e.g. Arial or Times New Roman) the more likely it is to use shape hinting rather than a truly mathematical representation of the final vector image. That's why it's sometimes better to use a bitmap font, which has been specifically designed for viewing at a small size, rather than a vector font outline. But the drawback to this is that bitmaps won't scale up successfully.

    Also remember that the placement of a font has a bearing on its readability which can be seriously compromised when it's scaled. When a font is initially drawn Flash will attempt to place the font onto the minimum permissible point on the screen. So, if your 12 pt font is to be positioned on an _x value of 25.05, Flash will do its best to place it there. Unfortunately, when you subsequently try to scale a font up or down, you are likely to get compounded errors with the mathematical rendering of the line and curve data, e.g. attempting to place a font on an _x value of 30.006 or 45.3847.

    For this reason, Flash ignores values such as points or pixels. Internally it converts all pixel measurements into twips or twentieths of a typographical point. That's why the minimum placement of any sprite, movieclip or font onto the stage is .05 of a pixel. So values like 30.006 and 45.3747 will be converted into twips and rounded to the next closest .05 of a pixel.

    But that introduces another issue...which is that a monitor can only physically draw whole pixels. It can't draw .1, .5. or .5 of a pixel, only 1, 2, 5 pixels. So, ideally, you should only be positioning fonts (or any other object) on whole pixels in Flash. But, should you choose to use fractions of a pixel, Flash gives you the options to render a font differently (i.e. to place more emphasis on the shape hinting rather than the line/curve data or vice versa) using anti-alias for readability or animation. It's the combination of this minimum coordinate placement by Flash (.05 pixels), plus the minimum practical ability of a monitor (1 pixel), which can cause dynamically scaled fonts to appear jerky.

    Finally, as I've said, you have ways to get around having to embed the entire font outline into your SWF. I've already mentioned the use of a font library but you can also use dynamic characters if you've previously embedded a static textfield which contains those same characters. Onve they've been embedded into the SWF, those characters remain available subsequently regardless of whether they're in a dynamic, input, or static field.

    You also have the option of breaking a font apart so that you do have vector images of the characters. You can create symbols for each character you want to use and then, using code, replace the dynamic text in your textfields with movieclip instances of each respective character. You can then scale these movieclips up and down successfully. Whether this results in a smaller SWF filesize depends on the size of each character symbol compared to the size of the embedded font outlines. Use the Generate Report option in your Publish settings to determine which is the best option for you.
    2006-11 GlosRFC - Searching 8,168,684,336 brain cells

  10. #10
    In some ways the Flash IDE is better than Flex.

    Flex has limited options for embedding fonts.

    The IDE can embed just lowercase, just uppercase, just numbers, or even just a handful of individual characters, if that's all you need.

    Not only that, but in Flash you can manually type out your text, press ctrl+b twice, and it is transformed to vector graphics.

    Eclipse or Flexbuilder that

  11. #11
    An old thread, but still relevant:
    2006-11 GlosRFC - Searching 8,168,684,336 brain cells

  12. #12
    There's no point in being super zealous about using code when embedding it into a textfield, wrapping the textfield into a sprite and exporting that sprite as a base class/whatnot will give you the same result, but without the whole chinese and japanese character sets.

    The goal is to find a balance hey

  13. #13
    It is possible to choose which characters you wish to embed with Flash CS4, via ActionScript only. Although this will require you to point CS4 to your Flex SDK since it will use the [Embed] tag.

    For information, embedding Arial basic latin takes me about 8kb. Adding all French characters takes it to 9kb.

    Here's the code I usually use :

    		[Embed(	systemFont = "Arial", 
    		fontName = "RegularArial", 
    		fontWeight = "regular",
    		fontStyle = "regular",
    		mimeType = "application/x-font", 
    		unicodeRange = "U+0020-U+007E" )]
    		private var RegularArial:Class
    After that it's your regular embedding thing with a TextFormat.

    You can also :
    - add accents and special characters by modifying the Unicode.
    - embed another font by changing the fontWeight to "bold" or the fontStyle to "italic".
    - embed at runtime by putting this code into a different swf, but in this case don't forget to register the font.

    Hope it helped. Any question, don't hesitate. And who would take money from you ? You're always helping people for free.
    Last edited by Aurelien; November 30th, 2009 at 12:29 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012