CSS in TextField

Hello.

I’m trying to apply css to a textfield as follows:

Toolkit.init();

var testText:TextField = new TextField();
var testSS:StyleSheet = new StyleSheet();

testSS.parse("i {color: #00FF00;} b {color: #0000FF;}");

testText.styleSheet = testSS;
testText.htmlText = "<i>" + "Hello" + "</i>" + " " + "<b>" + "world" + "</b>";

But it doesn’t seem to work (all text is the same color). Is there a way to make this work?

Hi Terron,

So unfortunately that isnt going to work. The htmlText is passed off to the host framework and it then processes it. So at that stage it has nothing to do with haxeui anymore. Even the tags that you can use in htmlText are going to vary from one framework to another. Which framework are you targeting?

Something like this should probably work:

.htmlText = "<font color='#00FF00'>Hello</font><font color='#0000FF'>World</font>";

Cheers (and welcome!)

Ian

Thanks for your reply.

I am using openfl and target html5. But openfl doesn’t implement StyleSheet class from flash, and I thought haxeui could help.

Right, so with haxeui, haxeui styles only apply to haxeui components… It doesnt apply to the host framework (at all). So if, for example, you wanted to style an openfl sprite with haxeui then you wont be able to, not without creating a haxeui component - in reality haxeui components (in openfl) end up as sprites so technically you can style a sprite, but you defo cant style openfl .htmltext with haxeui styles.

The htmlText code above using <font ...> should work for you, i know openfl supports that

Sorry its not what you wanted to hear :slight_smile:

Cheers,
Ian