ActionScript 3 带椭圆的文本字段限制

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 带椭圆的文本字段限制相关的知识,希望对你有一定的参考价值。

var myCopy:String = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras ullamcorper est in nibh. Integer dapibus, nisi at venenatis ullamcorper, metus eros vulputate nisi, in luctus erat sapien a mauris.\n\nSuspendisse dolor ipsum, congue at, commodo id, consectetur vel, dui. Donec vehicula egestas nibh. Aliquam imperdiet ligula a dolor. Praesent nec tortor id orci semper consectetur. Vivamus dictum lorem nec libero. Maecenas a pede. Aliquam felis nulla, adipiscing in, scelerisque et, rhoncus a, ipsum.\n\nPellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Maecenas rutrum augue at nulla. Vivamus egestas ornare sapien. Nunc lobortis. Aliquam auctor urna quis justo. Suspendisse elit orci, gravida eleifend, suscipit ac, porta ultrices, nibh. Morbi dignissim mauris varius magna.";

copy_txt.height = 150; // HEIGHT MUST BE SET BEFORE APPLYING TEXT TO TEXTFIELD.
copy_txt.text = myCopy;

var lastLine:String = copy_txt.getLineText(copy_txt.bottomScrollV - 1);
var visibleLength:uint = copy_txt.getLineOffset(copy_txt.bottomScrollV - 1);

// REMOVE TRAILING SPACES FROM LAST VISIBLE LINE OF TEXT
while(lastLine.substr(-1, 1) == " ")
{
	lastLine = lastLine.substr(0, lastLine.length - 1);
}

var lastLineWords:Array = lastLine.split(" ");

/* IF LAST WORD DOES NOT HAVE A RETURN OR PERIOD AT
   THE END, REPLACE LAST WORD WITH AN ELIPSE */
var lastChar:String = lastLineWords[lastLineWords.length - 1].substr(-1, 1);

if (lastChar != "." && lastChar.charCodeAt(0) != 13 && lastChar.charCodeAt(0) != 10)
{
	lastLineWords[lastLineWords.length - 1] = ". . .";
}


var myNewCopy:String = myCopy.substr(0, visibleLength) + lastLineWords.join(" ");

copy_txt.text = myNewCopy + " "; // SPACE ADDED AT END SO TEXT DOESN'T WRAP UNNECESARILLY.

以上是关于ActionScript 3 带椭圆的文本字段限制的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 限制文本字段中的行

ActionScript 3 限制输入文本字段中的行数

堆叠动态文本字段 Flash/ActionScript 3

ActionScript 3 简单椭圆长弦

ActionScript 3 计算椭圆

ActionScript 3 自动更改文本大小以适合文本字段