开发者

Actionscript 3.0 TextField displayed characters

I have a single line text field that gets his .text property populated from a external .XML file. This text is pretty long and I want to display it on one line as开发者_开发技巧 much as I can and add a "..." afterwards.

e.g.

whole text = Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

displayed text = Description: Lorem ipsum dolor sit amet, consectetur adipisicing el

how I want it to be displayed = Description: Lorem ipsum dolor sit amet, consectetur adipisicing...

I read the manual and I can't seem to find a property that gives me the index which points me to the end of the displayed text.

If you have another idea, please tell me.

Thank you!


Take a look at the examples for the TextLineMetrics class. That should get you going.


mytextfield.getLineLength(0)

should give you the length, in characters, of your first line of text. This should more or less correspond to the position of the last displayed character on the first line.

Adjust accordingly for other lines of text.


Can't you just use a substring?

var longtext:String = "Hello my really long string.";
var summary:String = longtext.substring(0,5);
SomeText.text = summary+"..."; // Hello...  


I always use the .length property. There are also the .setSelection, .replaceSelectedText methods that you can use with the .caretIndex property. Also This page is your friend http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html#propertySummary.

I've used these a bunch in textfields with special sizing needs. In the example below t is my textfield.

t.setSelection(t.length,t.length);
t.replaceSelectedText("");

You can just add whatever extra text in the quotes inside the replaceSelectedText method. You may need to adjust the caretIndex after that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜