[SOLVED] Trouble with ttf font and flash target

Hey,

I am trying to use the marker felt font in an openfl porject. When targeting flash, the font is not displayed.

I use stablexui, but it should roughly translate to this:

    var fontName = Assets.getFont('fonts/markerfelt.ttf').fontName;
    text.format.font = fontName;

This works for linux targets, but on flash target the font is not displayed (other fonts are, but they are in otf format).

Is it because it is ttf? Unfortantly I cannot convert it.
Or what could this be?

Thanks!
Nathan

What version of OpenFL/Lime?

I assume you meant to type “text.defaultTextFormat.font” rather than “text.format.font”? The latter doesn’t exist, as far as I know.

Anyway, this has to do with how Flash’s getters work. “text.defaultTextFormat” returns a copy of the TextFormat object, and modifying that copy won’t change anything. Instead, try this:

var fontName = Assets.getFont('fonts/markerfelt.ttf').fontName;
text.defaultTextFormat = new TextFormat(fontName);

Hey,

I am sorry, it turns out I did a stupid mistake at another position. I initilized the font name in a static variable like this:

static var fontName = Assets.getFont('fonts/markerfelt.ttf').fontName;

That worked on mobile, but not on flash. Problem solved, sorry for the unnecessary post. And thanks for the replies!

Out of curiosity, I wonder why is there a difference between platforms.
Because initializing a static property like this shouldn’t really work, as far as I know, unless Haxe can resolve it in compile time (simple types, for example). In both case, it seem that it should either work, or not work on both platform.
Why do such a difference exist?

I have no Idea, but maybe

Assets.getFont('fonts/markerfelt.ttf').fontName;

behaves different when invoked so early?!?

What is the value when you do it on Flash in a static?

It is:

null

Best,
nathan

You should be able to just use the font name in current versions, if you want, so you have it hardcoded, like “Arial Bold”

I do think that using these things in static variables are fraught with peril :wink: