Length of text

Does anyone know how to determine the length of whats in a dynamic text field once an external .txt is loaded?

What I’m trying to do is find the value so that if it exceeds a certain number of characters I can set a scroll bar to _visible = true;

Well, TextField.length is the function, but why don’t you just use MX’s scrollBar components, and set them to auto? It’d be easier. Oh well, I guess you probably thought of that.

No I didnt think of that. I am using a scrollbar component but how do you set it to auto?

Ah, I see the problem. Drat. The bastards at macromedia only added an auto/true/false state to the “scrollPane” component, which really doesn’t work with dynamic text (or at least I haven’t yet been able to make it work). So I guess you’ll have to do it your way using the TextField.length function.

Well I figured it out. Here’s the solution:

_root.bar._visible = false;
loadText = new loadVars();
loadText.load(“text1.txt”);
loadText.onLoad = function(success) {
if (success) {
newsBox.html = true;
newsBox.htmlText = this.myNews;
textLength = this.myNews.length
if (textLength > 180) {
_root.bar._visible = true;
}
}
}

The if statement condition may vary depending on your text box size. Here, I set the bar to be visible if there are more than 180 characters in the .txt file.

:q:

Why not just use [AS]if (textFieldInstanceName.maxScroll > 0){
bar._visible = true;
}[/AS]

[edit]lemme test this…lol[/edit]

Ok this works :slight_smile:

[AS]if (tf.maxscroll>1) {
bar._visible = true;
} else {
bar._visible = false;
}[/AS]

Where tf is the textfields instance name and bar is the instance name of the scrollbar.