views:

24

answers:

2

I basically have the same question as bder on the actionscript.org forums, namely if I can have my text anti-aliased if it is using an embedded font (Myriad Pro) to assign it to the htmlText property of a TextField and styling that with CSS.

Everything works fine with the text embedding and styling (the font is the one I want, and all its variations - bold, italic - are shown correctly), except that it looks bad, i.e. not anti-aliased. Of course, I have tried setting the antyAliasType and gridFitType properties to all possible combinations. Any ideas?

Oh, and I also tried writing my code exactly like in the example here, but did not work either, not sure why.

Thank you.

A: 

Actually I just made something this morning that used and embedded font so it was easy to test and see, and yes, when I changed the text property to the htmlText property of the textfield to <a href='http://www.google.com/'&gt;&lt;u&gt;google&lt;/u&gt;&lt;/a&gt; It produced a underline link and it has the antiAliasType set to AntiAliasType.ADVANCED.

Only thing is I am using a TextFormat rather than CSS.

My code is

        var myFont:Font = new Font1();

        quote = new TextField();
        quote.selectable = false;
        quote.embedFonts = true;
        quote.antiAliasType = flash.text.AntiAliasType.ADVANCED;

        quote.htmlText = "<a href='http://www.google.com/'&gt;&lt;u&gt;google&lt;/u&gt;&lt;/a&gt;";

        tf = new TextFormat();
        tf.font = myFont.fontName;
        tf.size = 24;
        tf.color = 0xffffff;
        tf.align = "center";

        quote.setTextFormat(tf);

Let me know if you have any questions.

Billy
hey Billy, thanks for the suggestion. Though we have to use CSS, and that seems to be the crux of the problem. But in the meantime I have found the solution, I will post the answer in a sec.
A: 

This thread helped. The trick is to assign a TextFormat instance (with the correct default font) to the defaultTextFormat property of the TextField instace. So the whole code becomes

        var tf : TextField = new TextField();
        tf.selectable = false;
        tf.width = w;
        tf.height = h;

        tf.autoSize = TextFieldAutoSize.LEFT;
        tf.antiAliasType = AntiAliasType.ADVANCED;
        tf.gridFitType = GridFitType.PIXEL;
        tf.wordWrap = true;
        tf.multiline = true;
        tf.embedFonts = true;

        var tff : TextFormat = new TextFormat();
        tff.font = "Myriad Pro";
        tf.defaultTextFormat = tff;

        tf.styleSheet = _styles;

I hope this saves someone a headache.