English 中文(简体)
Embedding Fonts in AS3 - Dynamic Text Field disappears
原标题:

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?

最佳回答

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!

问题回答

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.

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

import:

import flash.text.Font;

in your constructor:

Font.registerFont(MoolEmbed)

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





相关问题
Java (AWT): fitting text in a box

I have an application that extends a Frame. Then, it ll display a few lines of text using: Font f = new Font("Arial", Font.PLAIN, 10); g.setFont(f); g.drawString("Test|great Yes ^.", x, y + 10); Now ...

Embed font into PDF file by using iText

I defined a tag map, and got a XML data file. I want to convert the XML data file to PDF by using iText. The question is how to embed fonts (e.g. Polish font, Chinese font) into the target PDF when ...

Font Rendering between Mozilla and webkit

I m not sure if this has anything to do with the recent Safari update, but I m beginning to notice this a lot. There is a drastic difference in the way each browser is rendering fonts. for instance, ...

Embedding Fonts in AS3 - Dynamic Text Field disappears

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, ...

Dynamic GD image width text

I m trying to spice up my website by using custom fonts for headings. For me, the most appropriate way to do this is using PHP and GD. I have written a little script which will output the dynamic text ...

How do I combine @font-face and @media declarations?

I d like to build a common typography stylesheet with a very small number of selectors. As such, I d far prefer to use @media sections for the various versions rather than create different files, each ...

热门标签