tags:

views:

739

answers:

1

HI Everyone, How can i find line number in events like mouse clicked, key down and key up. And also highlight that line with color. I used TextArea.

Thanks in Advance.

Regards, shivang

+1  A: 

The functionality you need is contained in TextField class. You should use getLineIndexAtPoint method of TextField to get the line under certain position.

But TextArea hides inner TextField class from user.

So, option one is to use UITextField. Option two is extending TextArea and implementing required functionality there.

Here is a quick prototype that should help you get started:

package test
{
import mx.controls.TextArea;
import flash.events.MouseEvent;
import flash.text.TextFormat;

public class HighlightTextArea extends TextArea
{
    public function HighlightTextArea()
    {
     super();
    }

    override protected function createChildren ():void
    {
     super.createChildren();
     textField.addEventListener(MouseEvent.CLICK, textField_clickHandler);
    }

    private function textField_clickHandler (event:MouseEvent):void
    {
     var lineIndex:int = textField.getLineIndexAtPoint(event.localX, event.localY);
     if (lineIndex == -1)
      return;
     var lineOffset:int = textField.getLineOffset(lineIndex);
     var lineLength:int = textField.getLineLength(lineIndex);
     if (lineLength > 0)
      textField.setTextFormat(new TextFormat(null, null, 0xFF0000), lineOffset, lineOffset+lineLength);
    }
}
}
Hrundik
Thanks for quick reply Hrundik. It works.....But how can i highlight background of particular line?Thanks again.
shivang