Issue with setTextFormat

Hello. I’m trying to create a 2 color text. For example if I have 1234567890 I want 1 and 890 in “prendido” color and the rest of the numbers in “apagado color”. I’m targeting HTML5. This is the code

		var apagado:TextFormat = new TextFormat(Assets.getFont("fonts/wwDigital.ttf").fontName, 25 , 0);
		apagado.color = 0x2B0E0A;
		

		var prendido:TextFormat = new TextFormat(Assets.getFont("fonts/wwDigital.ttf").fontName, 25 , 0);
		prendido.color = aColor;

		var myTextField:TextField = new TextField();
		myTextField.width = 145;
		myTextField.autoSize = TextFieldAutoSize.LEFT;
		myTextField.defaultTextFormat = apagado;
		myTextField.embedFonts = true;
		myTextField.text = toWrite;
		
		myTextField.setTextFormat(prendido, 0, 1);
		var aPrender = 3 + aInteger.length;
		trace('prende' + aPrender);
		myTextField.setTextFormat(prendido,10-aPrender,10);

If I run it as is, all the text is changed to “prendido”. If I comment this line “myTextField.setTextFormat(prendido,10-aPrender,10);” it stills renders in prendido color. Only when I also comment this line (both lines commented)“myTextField.setTextFormat(prendido, 0, 1);” The text renders in apagado color.

Any clues?

Regards
Luis

ok I saw in Evoland a way of changing colors within a text, I don’t know if it will help you because it is a hardcoded way, nothing “automatic” unless you make it that way.

anyway the thing is using myTextfield.htmlText instead of myTextfield.text

so your text will look like myTextfield.htmlText = “<color=’#FFFFFF’>This part will be in white</color> <color=’#2B0E0A’>and this part un apagado</color>”;

But if you know you way around strings you can have a function to place those strings “<color=’”+youColor+"’>" and “</color>” within your text then you are sorted out.

but for more info take a look at TextField class and you’ll see the htmlText thing and how it works.
Good Luck and Hope it helped.

I tested but it didn’t worked. Seems to be something really simple, but I can’t find any walkaround.

Thanks anyway.
best regards
Luis

Actually yes you are right, I had made a mistake. the code should have been like this:

myTextField.htmlText = "<font color='#00ff00'>hello</font> there";

it works on:
openfl: 2.2.8
lime: 2.1.3
hxcpp: 3.1.64

when I updated them to the latest:
openfl: 3.0.3
lime: 2.3.3
hxcpp: 3.2.94
the string inside the font tags goes all blank

Try the latest version, EvolandClassic appears to be working here in HTML5