PDA

View Full Version : Number of text field lines


fido_glc
08-16-2007, 01:15 PM
I am loading some text into a multiline size defined text field. How can I, after I load the text, get the number of lines that the text field has ?

CyanBlue
08-16-2007, 02:16 PM
You do see the line in the textField visually, but there is no actual line number you can get...

fido_glc
08-16-2007, 02:44 PM
You do see the line in the textField visually, but there is no actual line number you can get...
There has to be a way to find out how many lines there are.

matbury
08-19-2007, 04:27 AM
Yes, there is. I'll look it up...

matbury
08-19-2007, 04:32 AM
According to Flash help:

maxscroll (TextField.maxscroll property)
public maxscroll : Number [read-only]

Indicates the maximum value of TextField.scroll.

Availability: ActionScript 1.0; Flash Player 6

Example
The following example sets the maximum value for the scrolling text field my_txt. Create two buttons, scrollUp_btn and scrollDown_btn, to scroll the text field. Add the following ActionScript to your FLA or AS file.

this.createTextField("scroll_txt", this.getNextHighestDepth(), 10, 10, 160, 20);
this.createTextField("my_txt", this.getNextHighestDepth(), 10, 30, 320, 240);
my_txt.multiline = true;
my_txt.wordWrap = true;
for (var i = 0; i<10; i++) {
my_txt.text += "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh "
+ "euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.";
}
scrollUp_btn.onRelease = function() {
my_txt.scroll--;
scroll_txt.text = my_txt.scroll+" of "+my_txt.maxscroll;
};
scrollDown_btn.onRelease = function() {
my_txt.scroll++;
scroll_txt.text = my_txt.scroll+" of "+my_txt.maxscroll;
};


The MovieClip.getNextHighestDepth() method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components DepthManager class instead of the MovieClip.getNextHighestDepth() method.

pureDesi
08-19-2007, 05:29 AM
Here ya go, made a quick little function that does exactly what you need.

function getLines(t:TextField):Number {
if (t.multiline === false){
return 1;
}
var prevScroll:Number = t.scroll;
var returnNo:Number;
t.scroll = 0;
returnNo = t.bottomScroll+--t.maxscroll;
t.scroll = prevScroll;
return returnNo;
}

// Example useage:
// name_txt is a multiline TextField

trace ( getLines(name_txt) );

CyanBlue
08-19-2007, 07:13 PM
Maybe I am approaching this from the wrong way, but what you guys have is basically the translation of the maxscroll value and that is not something we can really utilize to get the content of the specific line...

pureDesi
08-19-2007, 09:19 PM
I don't think he was trying to find the content of a specific line.
I am loading some text into a multiline size defined text field. How can I, after I load the text, get the number of lines that the text field has ?
Just how many lines the text occupies.
Can you clarify fido_glc?