A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: limit number of lines in a textfield

  1. #1
    Junior Member
    Join Date
    Apr 2003
    Posts
    17

    limit number of lines in a textfield

    Hi there!

    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.

    Thanx!!

  2. #2
    Senior Member
    Join Date
    Jul 2002
    Location
    California
    Posts
    125

    I had the same problem...

    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!

  3. #3
    Senior Member
    Join Date
    Jul 2002
    Location
    California
    Posts
    125

    Oops.

    I guess I didn't attach the file. Gotta run now, but I'll try to figure out how to attach files tomorrow. Sorry!
    Attached Files Attached Files

  4. #4
    Senior Member
    Join Date
    Jul 2002
    Location
    California
    Posts
    125

    I don't know why the attachment worked that time!

    How bizarre!

  5. #5
    Junior Member
    Join Date
    Apr 2003
    Posts
    17
    I found this solution using code from another thread, what do you think about it?

    If LineLimit is exceeded, it cuts exceeding part. Im not really sure how but it works!


    LineLimit = 20
    myListener = new Object();
    myListener.onKeyUp = function() {

    // 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);

  6. #6
    Senior Member
    Join Date
    Jul 2002
    Location
    California
    Posts
    125
    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center