Hi all,
I need to restrict user input to a certain number of lines in a textfield.
Flash 8, AS2.
After an extensive search something like this showed up:
//txtFld is obviously the TextField, n is the max number of lines
shrinkString = function (txtFld, n:Number):Void {
var l = txtFld.text.length;
for (var i = 0; i<l; i++) {
txtFld.scroll = txtFld.maxscroll;
if (txtFld.bottomScroll>n) {
txtFld.text = txtFld.text.slice(0, -1);
} else {
break;
}
}
};
myTextField.onChanged = function() {
shrinkString(this, 10);
};
This is close to what I need but it has a major drawback; it simply cuts off
the text at the end. So when a user inserts a 'return' an entire line of
text disappears. I could change the TextField into a single line,
eliminating carriage returns. But that is not quite what I'm looking for.
Is there a way to catch/detect key presses before they effect the contents
of a TextField. And then get rid if them -unless it's the delete/backspace
key-?
Or is there any other way to block addition of text when a certain maximum
of lines has been reached?
I would really appreciate any help since this problem has been bothering me
for quite some time now.
Rob
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com