Skip to main content
Inspiring
May 18, 2023
Question

AS3, text auto-scrolling problem when textfield "MOUSE_OVER"

  • May 18, 2023
  • 1 reply
  • 184 views

Sorry if this is a duplicate question.
No matter how much I try, I can't find a solution, so I'm asking for help.
When "index == -1" at the first execution, the textlist automatically scrolls to the bottom,
When I move the scroll bar (UIScrollBar) and then move the mouse pointer into the textfield, the textlist is not fixed and jumps to the wrong place.

Is there a way to completely freeze the textlist on "MOUSE_OVER" without using "scrollV"?

Thanks in advance.

// tf => textField

lineHighlight(tf);

function lineHighlight(tf):void {
	tf.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
	tf.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
}

function mouseOverHandler(e:MouseEvent):void {
	stage.focus = e.currentTarget as InteractiveObject;
}

var fsCount:Number = 0;
function mouseMoveHandler(e:MouseEvent):void {
	++fsCount;
	var index:int = e.currentTarget.getLineIndexAtPoint(e.localX, e.localY);
	
	var sPos:Number = e.currentTarget.scrollV; 
	if ((index == -1) || (index >= e.currentTarget.bottomScrollV)) {
		if (fsCount < 30) {
			e.currentTarget.scrollV = e.currentTarget.getCharBoundaries(0);
			//Prevent moving to the bottom if "index == -1" at first run
		} else {
			e.currentTarget.scrollV = sPos;
		}
		return ; 
	}
}
    This topic has been closed for replies.

    1 reply

    Inspiring
    May 25, 2023

    It's resolved. thank you