TextField.setTextFormat doesn't work on part of the field

I’m trying to use the setTextFormat method of TextField object:

var fontReg = Assets.getFont ("fonts/Titillium-Regular.otf");
var fontBold = Assets.getFont ("fonts/Titillium-Bold.otf");
var tfLabel = new TextFormat (fontReg.fontName, 36, 0x000000);
var tfLabelBold = new TextFormat (fontBold.fontName, 36, 0x000000);

var txtLabel = new TextField();
txtLabel.selectable = false;
txtLabel.defaultTextFormat = tfLabel;
txtLabel.embedFonts = true;
txtLabel.wordWrap = true;
txtLabel.autoSize = TextFieldAutoSize.LEFT;
txtLabel.text = "123456";
txtLabel.setTextFormat(tfLabelBold, 0, 3);

… but the beginIndex and endIndex parameters doesn’t seem to do anything. All the text is made bold. I tried using setSelection.

The .htmlText property works with font color, but <i> and even <b> tags will actually show up.

I’m targeting HTML5 and I have no idea how I will make part of a dynamic text italic if this doesn’t work…

bump - could anyone help me with this?

I don’t know, but I’ll make a couple guesses.

  • What if you tried setting tfLabelBold.bold = true?
  • Double check that fontReg.fontName != fontBold.fontName.
  • Try changing the color rather than the font: var tfLabelBlue = new TextFormat(fontReg.fontName, 36, 0x0000FF).
  • Do you need to update OpenFL or Lime?
  • If you’re already running the latest versions, try running this in OpenFL 3.3.3 and Lime 2.6.2. (Because OpenFL 3.3.4 changed something about text fields.)

Yes, I had tried using the .bold attribute - all the text is applied the format, regardless of the beginIndex and endIndex parameters. Same thing happens when trying to change colours that way. As I mentioned on the original post, loading .htmlText with <font color=''> seems to work to change only part of the content, but <b> and <i> do not - in this case, the tags will show up as text.

Now, how to run a project in a different Lime/OpenFL version? I couldn’t find anything in the official documentation or Google.

Thank you so much!

> haxelib install openfl 3.3.3
> haxelib install lime 2.6.2

Or if they’re already installed:

> haxelib set openfl 3.3.3
> haxelib set lime 2.6.2

Yep, no deal. The problem persists even under those versions.

Guess I’ll just make the background images with the text pasted on them…

Thank you for the help anyway.

The setTextFormat function has not been fully implemented yet.

See the source code here:


The default text format is being assigned but not actually applied in any way.

Ah. Nice catch. I could also see that when it comes to HTML tags there’s only a crude search for the tag and only font, size and color are implemented.

Thanks for confirming I should stop pursuing this.

Ah, so that’s the difference. It works for me because I’m using Legacy, and it doesn’t work for you because you’re using Next.