[HTML5] Can't get textField scrollV, numLines or length

Hi there, I was wondering if it is possible to get the number of lines in a dynamic textfield when target is HTML5. Works ok for flash.

I have something like:

var tf:TextField = new TextField();
tf.text = "Super long text blablabla...";

When I activate set wordWrap=true, I can see my textfield in multiple lines but for the code above, length returns null, and numLines as well as maxScrollV return 1.

Is there any way to scroll the text in HTML5?

Thanks for your time.

That’s because there is no new line, line feed, or carriage return characters in the string. numLines counts the number of lines, so you explicitly have to use “\n” as an example in your string for it to count correctly. maxScrollV counts how many lines can be scrolled by on the vertical axis before the TextField object reaches the bottom-most line in said field.

As for the length, I’m not sure why it would be returning null. Although the reason why could be because you haven’t added the object to the stage, and you ask for the length before you do that. I believe it counts characters once the TextField has been rendered, unless someone can correct me on that. I’ve never tested it like that.

Also scrolling text is possible by using the MouseEvent.WHEEL variable in an event, and using e.delta to determine which direction to scroll in.

Example code:

private function onTextFieldScroll(MouseEvent.WHEEL, function(e:MouseEvent) {
    if (e.delta > 0)
    else if (e.delta < 0)

Thanks for your answer.
I added “\n” and now it counts more than one line if I use textField.numLines.
However, maxScrollV still returns 1 and length returns null even though I tried to add the textfield to the stage before asking for it.

Textfield multine and wordWrap are set to true and there are lines which can’t be seen. If I target flash it works, but no luck for HTML5.

Work on TextField is ongoing, working on a big rewrite

1 Like

Just a little update :smile:

bottomScrollV, maxScrollV, maxScrollH, scrollH, scrollV, numLines, as well as many methods previously unimplemented should be available in the TextField class :smile:

It should be consistent for HTML5 and native. Expect it in the next release :success:

Awesome! Good to know.
Thanks :slight_smile:

I’d like to point out that I uploaded to OpenFl 3.3.0 and all these methods now work perfectly.
Thanks for your support!