How to get each line Info of TextArea?

Posted on 2009-04-24
Last Modified: 2012-06-27
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
Question by:bksaji
    LVL 2

    Accepted 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.) 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.

    Author Closing Comment

    Thanks for the solution, but i achieved by myself with the following code,

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
    Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now