• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1837
  • Last Modified:

How to get each line Info of TextArea?

I need to get each line information like linewidth, lineheight and font info. Here i have to consider the word wrap as new line, since i will send the each line information to server to create PDF for the respective TextArea as it looks.  please help me. i can give you donation if i satisfy. Thanks
1 Solution
Alright I've done some research on this, and I'm not entirely sure if it's possible, though it might be. I don't think it's possible to get individual line height (though if you set this in the Text component, you can get it from there) or the font info on a line-by-line basis. However getting the number of characters per line is, I believe, possible. What I've done is take a quick read through the adobe docs on a Text control and then the IUITextField control:


I believe the way you would access the IUITextField of any Label-based component is by calling on the textField property. Then you can call the IUITextField properties or methods directly. Something like:


Now the major problem I have is that I'm not near my home computer, so I can't test to see if any of this works. Also, although many of these IUITextField methods require a "lineIndex" (i.e. 0 is line 1, 1 is line 2, etc.), it doesn't appear that there is a simple property or method that returns the number of lines. Though given the available methods, I did think of a ghetto fabulous way of getting around this problem. Try to follow along :-)

So let's focus on these two methods:

getLineLength(lineIndex:int):int (Returns the number of characters in a specific text line.)
getLineText(lineIndex:int):String (Returns the text of the line specified by the lineIndex parameter.)

Alright...now let's operate on the assumption that if you add up the return values of getLineLength(i) from 0 to the last lineIndex, the sum will equal the return value of myText.text.length. What I'm saying is...the sum of the characters in each line will equal the total character length of the text. So you can do something like:

var currSum:Number = 0;
var totalCharacters = myText.text.length;
var textArrayCollection:ArrayCollection = new ArrayCollection();

for (var i:int=0; currSum<totalCharacters; i++) {
var currLineLength:Number = myText.textField.getLineLength(i);
var currLineText:String = myText.textField.getLineText(i);
var myObj:Object = new Object();

myObj.Length = currLineLength;
myObj.Text = currLineText;

currSum += currLineLength;

Now, if I haven't screwed it up (remember I'm going on memory here ;-), you've got, an ArrayCollection with all the necessary data. The way you would access this data would be:

otherTextInput.text = textArrayCollection[2].Text;

That will put the text from line three of your myText into some otherTextInput. The way you would iterate through this colection would be:

var numChil:Number = textArrayCollection.length;

for (var i:int=0; i<numChil; i++) {
textArrayCollection[i].Length //Returns the number of characters in the current line
textArrayCollection[i].Text //Returns the exact String of the current line

So that's that. Be sure to let me know if this somehow doesn't work.
bksajiAuthor Commented:
Thanks for the solution, but i achieved by myself with the following code,

var len:uint = textField.numLines;
for(var i:uint=0;i

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now