views:

39

answers:

3

I added a custom class for a custom font in the flash project library. Now when i try to embed the font and use it from actionscript , the text is not getting visible.

There is no error being thrown. Here is my code.

var tabfont:Font = new tabHeaderFont();

var format:TextFormat = new TextFormat();
format.font = tabfont.fontName;

tab.defaultTextFormat = format;
tab.embedFonts = true;

addChild(tab);

Can anybody figure out what is wrong with this.

+2  A: 

Have you tried the setTextFormat method of TextField to apply the text format instead of the defaultTextFormat property? Also, make sure setting the TextFormat is done after setting any properties in your TextFormat instance or they will not be applied.

        var tabfont:Font = new TabHeaderFont();
        var format:TextFormat = new TextFormat();

        format.font = tabfont.fontName;

        tab.embedFonts = true;

        tab.setTextFormat(format);
        addChild(tab);

You also need to make sure you set the TextFormat after setting the .text property of your TextField or the text will not appear.

dr_tchock
yes this was the issue. tab.settextFormat(format); when i used it like that instead of defaultTextFormat , it started working. Thanks buddy
Wind Chimez
A: 

Have you checked that the font is correctly embedded or not? If not, then field won't be visible. Use

Font.enumerateFonts()
to get the list of all available embedded fonts.

taskinoor
A: 

the main difference between defaultTextFormat & setTextFormat is when you actually apply the method.

Use defaultTextFormat when you format your TextField before defining your TextField text content, use setTextFormat when your Textfield text content has already been set.

In your code example, you don't mention when the text property is set.

Practically, if it works with one method, it should work with the other. It all depends on how you implement them

PatrickS