6

This is hopefully a new problem or just me missing something obvious. Please help! I'm embedding a font into my AS3 application. I'm doing everything by-the-book and it half-works.

In my main class,

    [Embed(source="Art/moolbor.ttf", fontFamily="MoolEmbed", 
        mimeType="application/x-font")]
    var MoolEmbed:Class;

Then later on in my code:

    var newFormat:TextFormat = new TextFormat();
    newFormat.font = "MoolEmbed";
    newFormat.size = 20;
    newFormat.color = 0xFCF374;

    year.autoSize = TextFieldAutoSize.LEFT;
    year.text = "Hello World";
    year.embedFonts = true;
    year.setTextFormat(newFormat);
    year.antiAliasType = "advanced";

This works perfectly fine, and the text shows up beautifully. I can rotate it, alphas apply to it, and it's nicely antialiased. The problem is that the textfield is dynamic - Later on in the code:

    year.text = "And a second hello world";

As soon as this code is triggered, the textfield disappears completely. I turn on

    year.border = true;

and I can see that the textfield is still there, but it's size has shrunk down to just a few pixels. Thinking perhaps it was the autoSize messing things up,

    //year.autoSize = ...;

Same problems. Thinking it might be embedding, I commented out the line:

    //year.embedFonts = true;

And the textfield returns to working status, but (Understandably) loses it's ability to do alphas and rotations.

Any idea what's going on?

Andy Moore
  • 865
  • 3
  • 16
  • 36

4 Answers4

13

I wrote a long talkative entry on possible reasons as why this would not work. But as I re-read you code I think i spotted the error. Change the row:

year.setTextFormat(newFormat);

To:

year.defaultTextFormat = newFormat;

That should do it!

grapefrukt
  • 27,016
  • 6
  • 49
  • 73
  • Thanks so much! Never used the defaultTextFormat property before... Learn something new every day! – Andy Moore Nov 18 '09 at 19:56
  • 1
    I have pretty much the same issue, this solution still isn't really working for me. Fonts.enamurate does show my embedded font. – Fahim Akhter Jul 27 '11 at 11:39
  • thanks, saved me allot of work. However, in my case I had to add instead of change. – Frank Sep 24 '12 at 18:59
  • Ten Years later, still this is a helpful post. I followed the same instructions here, but it setting the font to antialiasing was what it made it work for me. Thank you all. – FlashV8 Apr 20 '22 at 04:29
3

as defaultTextFormat didnt work for, a combination of the other two tips worked

import flash.text.Font;

in your constructor:

Font.registerFont(MoolEmbed)

and then

After you set the text property for the second time make sure you call setTextFormat(newFormat) again.

hannes
  • 31
  • 1
0

you need to register your font with the global font list.

import:

import flash.text.Font;

in your constructor:

Font.registerFont(MoolEmbed)
greggreg
  • 11,945
  • 6
  • 37
  • 52
0

After you set the text property for the second time make sure you call setTextFormat(newFormat) again.

heavilyinvolved
  • 1,575
  • 1
  • 11
  • 12