Hi.
Here is a simple approach. You can elaborate it more to change the highlight color or you can also use the setTextFormat method to change the character colors instead.
AS3 code:
import flash.display.DisplayObject;
import flash.display.InteractiveObject;
import flash.events.MouseEvent;
import flash.text.TextField;
function main():void
{
var i:int;
var child:DisplayObject;
for (i = numChildren - 1; i > -1; i--)
{
child = getChildAt(i);
child.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
child.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
}
}
function mouseOverHandler(e:MouseEvent):void
{
stage.focus = e.currentTarget as InteractiveObject;
}
function mouseMoveHandler(e:MouseEvent):void
{
var edges:Object = getLineEdges(e.currentTarget as TextField, e.localX, e.localY);
e.currentTarget.setSelection(edges.firstIndex, edges.firstIndex + edges.lineLength);
}
function getLineEdges(tf:TextField, pointerX:Number, pointerY:Number):Object
{
var charIndex:int = tf.getCharIndexAtPoint(pointerX, pointerY);
if (charIndex == -1)
return {};
var lineIndex:int = tf.getLineIndexOfChar(charIndex);
var firstIndex:int = tf.getLineOffset(lineIndex);
var lineLength:int = tf.getLineLength(lineIndex);
return { firstIndex: firstIndex, lineLength: lineLength };
}
main();
Files / source / code / download:
https://bit.ly/454awMD
I hope it helps.
Regards,
JC