i need to limit the number of lines in a text field... Can any one help?
I know how to limit the number of characters, but that's no good. I need to limit the text field so that it prints in 2 pages. First I just counted the number of chars, but someone could insert several returns, the max number of chars would not be reached but it would still not fit in the printed page.
And I came up with a very half-assed solution. Best I could do though, so you're welcome to it. I'm attaching the .fla. One thing - in this example, if the maxscroll is over 7, that means the user has entered more than 10 lines in the textfield. Kind of a pain, because it means if you change the size of the textfield, you have to fiddle around to figure out the new numbers. Good luck!
// number of lines showing in myText:
numlines = (myText.bottomScroll-myText.scroll)+1;
// number of lines you can scroll down:
myMaxScroll = myText.maxscroll;
// total number of lines:
myTotalLines = numLines+(myMaxScroll-1);
//trace(myText.text.length)
if (myText.length>limite || myTotalLines>LineLimit) {
trace("ya se paso")
myText.text = myText.text.substr(0,Text.text.length-1);
}
};
Key.addListener(myListener);
I really, really like that this solution lets me to say exactly how many lines I want to allow. I was never happy about my solution being so dependant on the height of the textbox.
But when I tried it, it only seemed to trim the very last character entered. If your user copies and pastes a chunk of characters, they'll still be able to enter more than the maximum you want to allow them to - try it. I want a solution that trims the number of characters necessary to keep the user from going past the maximum no matter how they enter stuff.
I'll have to keep thinking about this. Do please let me know if you find out anything else...