在舞台上我有一个文本字段,我的目标是能够在不使用UIScroller的情况下滚动文本字段,我想通过仅向上或向下拖动鼠标来滚动文本字段。它不行...
textfield.addEventListener(MouseEvent.MOUSE_DOWN, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
textfield.addEventListener(MouseEvent.MOUSE_MOVE, fl_MouseClickHandler3);
}
function fl_MouseClickHandler3(e:MouseEvent):void
{
if(stage.mouseY+1){ //when the cursorY goes down the text goes down too
textfield.scrollV++;
}
if(stage.mouseY-1){ //when the cursorY goes up the text goes up too
textfield.scrollV--;
}
}
我让这段代码工作了,但是,您还有其他问题需要解决:
- 当用户拖动到 TextField 对象外部,然后再次将鼠标悬停在 TextField 上时,处理程序将再次触发,因为鼠标移动侦听器从未被删除。
- 需要微调要应用的滚动量,以正确考虑文本字段中的文本量。 我没有调整它,因为我不想实现超出您的设计要求的东西。
试试这个代码:
textfield.addEventListener(MouseEvent.MOUSE_DOWN, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
textfield.addEventListener(MouseEvent.MOUSE_MOVE, fl_MouseClickHandler3);
}
function fl_MouseClickHandler3(e:MouseEvent):void
{
if( stage.mouseY > e.target.y + e.target.height / 2){ //when the cursorY goes down the text goes down too
textfield.scrollV++;
} else {
textfield.scrollV--;
}
}