Flash AS3: crop TextField content off at X lines, add '...' at the end

Posted by matt lohkamp on Stack Overflow See other posts from Stack Overflow or by matt lohkamp
Published on 2010-04-08T19:03:44Z Indexed on 2010/04/08 22:13 UTC
Read the original article Hit count: 420

There's only room for three lines of text in the interface, but the content is external and variable, and if it ends up taking up more than three lines, there needs to be some sort of 'view all' button functionality. I can kind of think about what that function needs to look like, but I'm not quite sure what the best way to do it in AS3 would be. Something like (in pseudo code):

function cropText(source:TextField, length:int, append:String):TextField{
    if(source.lineCount > length){
        source.text = // magic function that retuns the first length lines,
        // minus append.length characters, with the append value tacked onto the end
    }
    return source;
}

... right? How would you fill in the missing bit?

© Stack Overflow or respective owner

Related posts about flash

Related posts about as3