【问题标题】:Flash AS3: crop TextField content off at X lines, add '...' at the endFlash AS3:在 X 行处裁剪 TextField 内容,在末尾添加“...”
【发布时间】:2010-04-08 19:03:44
【问题描述】:

界面中只有三行文本的空间,但内容是外部和可变的,如果最终占用超过三行,则需要某种“查看全部”按钮功能。我可以考虑一下该功能需要是什么样的,但我不太确定在 AS3 中实现它的最佳方法是什么。类似的东西(在伪代码中):

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;
}

...对吗?您将如何填写缺失的部分?

【问题讨论】:

    标签: flash actionscript-3 textfield utilities


    【解决方案1】:

    类似...

    private function cropText(source:TextField, length:int, append:String):TextField {
        if (source.numLines > length) {
            source.text = source.text.substr(0, source.getLineOffset(length) - append.length) + append;
        }
    
        return source;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-30
      相关资源
      最近更新 更多