PDA

View Full Version : length of text



pspecial
July 2nd, 2003, 11:53 AM
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;

Meltdown
July 2nd, 2003, 12:11 PM
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.

pspecial
July 2nd, 2003, 02:02 PM
No I didnt think of that. I am using a scrollbar component but how do you set it to auto?

Meltdown
July 2nd, 2003, 02:24 PM
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.

pspecial
July 2nd, 2003, 03:01 PM
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.

lostinbeta
July 2nd, 2003, 03:37 PM
:q:

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

lemme test this...lol

lostinbeta
July 2nd, 2003, 03:43 PM
Ok this works :)

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

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