views:

29

answers:

4

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!

A: 

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

grapefrukt
A: 

Guys I can't seem to truncate my text. Can you show me an example of sorts on how to make the large text X into a text that fits TextField Y on the stage.

I tried with labels but I can't seem to truncate it.

Lupuleasa
A: 

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.

larsiusprime
A: 

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...  
woodscreative