The correct way of implementing rich text

What is considered the correct implementation of any kind of rich text support? Like I want certain segments of my text to have effects such as bold, italics, and colour applied to them. In AS3 we used htmlText and now I think they use TLFText?

But htmlText isn’t very well supported, is rich text currently possible outside the Flash target?

You should be able to use the setTextFormat() method, but at the moment, that changes the entire text field. Hopefully they’ll fix it soon.

For now, try downgrading to OpenFL 3.6.1 and Lime 2.9.1. These have a “Legacy” mode that implements setTextFormat() correctly. To enable it, add this to project.xml above the <haxelib /> tags:

<set name="openfl-legacy" />

It would really need to be different segments. Is there no way for me to do this other than writing my own text renderer?

As I said, you can downgrade and use Legacy mode. Is there some reason you don’t want to do that?

Oh I see after looking at the function definition. Although it does mess up a lot of my code if I downgrade, is there any way I could import this class into OpenFL 4.0.0?

The two TextField implementations are entirely incompatible, so there’s no way to import the legacy one.

Fortunately, it looks like the new implementation has partial support for different formats for different text. The problem is, setTextFormat() doesn’t use that.

You may be able to update setTextFormat() to add entries to the textFormatRanges array. Since I don’t know much about this implementation, I don’t know if it would be that simple. Just to be on the safe side, keep your TextFormatRanges in order, and don’t let them overlap.

My version of openfl has setTextFormat fully implemented:

If you’re interested, here is the commit.

1 Like