Can't get a font to be applied to text field in flash target

import flash.text.Font;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;

@:font("assets/fonts/Verdana.ttf") class VerdanaNormal extends Font { }
class FontsFL {
	public static var VERDANA;
}
class TitleCardFL extends TitleCardBase
{
	var title:TextField;
	
	public function new() 
	{
		super();
		
		Font.registerFont(VerdanaNormal);
		FontsFL.VERDANA = new VerdanaNormal().fontName;
		
		this.title = new TextField();
		this.addChild(this.title);
		this.title.selectable = false;
		this.title.x = this.title.y = 6;
		this.title.width = 120;
		this.title.text = "OpenLR";
		this.title.defaultTextFormat = new TextFormat(FontsFL.VERDANA, 24, 0xCC00CC);
    }
}

The above is more or less how I’m trying to execute it. I get no errors, my code compiled successfully, but the text field does not reflect the changes I have outlined when calling this.title.defaultTextFormat = new TextFormat(FontsFL.VERDANA, 24, 0xCC00CC);

Try setting defaultTextFormat before you set text, or you can use setTextFormat (title.defaultTextFormat) if you need to apply it after :slight_smile:

This solved the size and color issue, but it’s not using the font I want to use.

On HTML5, you need to use webfonts. You can do this by adding custom CSS to your own “index.html” template, but we also do it by default automatically if you include fonts in your asset directory

For example:

1.) Make sure “assets/fonts/Verdana.ttf” is included in your project file (such as <assets path="assets" />)
2.) Use "Verdana" or Assets.getFont ("assets/fonts/Verdana.ttf").fontName (these should be the same… the name embedded inside the font)

It works fine for HTML5. My issue is on the flash target as the title says.

Hmm, well see if it works the way I described for Flash is well (comment out the @:font embed)

This worked, thank you!

1 Like