Skip to main content
Inspiring
October 1, 2008
Answered

Disabling mouse wheel scrolling on a TextArea?

  • October 1, 2008
  • 1 reply
  • 1860 views
I'm pretty familiar with Actionscript, and this one has me completely stumped. What I'm trying to do is to prevent people from scrolling a TextArea with their mouse wheel, as the TextArea is inside of a ScrollPane, and at the moment scrolling one will scroll the other (double scrolling). Initially I tried:

tArea.textField.mouseWheelEnabled = false;

However, this didn't work. After doing some research I found some suggestions to override the childrenCreated function of my class that extends TextArea, ala

override protected function childrenCreated():void {
super.childrenCreated();
textField.mouseWheelEnabled = false;

}

but this will only work in Actionscript 2. Finally after doing some more research, I found some suggestions to intercept and disable events, ala


this.addEventListener(ScrollEvent.SCROLL, this.disableScrollHandler);
textField.addEventListener(MouseEvent.MOUSE_WHEEL, disableMouseHandler, true);
verticalScrollBar.addEventListener(MouseEvent.MOUSE_WHEEL, disableMouseHandler, true);
addEventListener(MouseEvent.MOUSE_WHEEL, disableMouseHandler, true);
textField.addEventListener(MouseEvent.CLICK, disableMouseHandler, true);
verticalScrollBar.addEventListener(MouseEvent.CLICK, disableMouseHandler, true);
this.addEventListener(MouseEvent.CLICK, disableMouseHandler, true);
.
.
.
function disableMouseHandler(event:MouseEvent):void {
trace("disableClickHandler");
event.preventDefault();
event.stopPropagation();
}
function disableScrollHandler(event:ScrollEvent):void {
trace("disableClickHandler");
event.preventDefault();
event.stopPropagation();
}

But this failed as well. Did I doing something wrong? Is this just not possible? What's the deal here?

Thanks,
Stephen M.
This topic has been closed for replies.
Correct answer slmille4
Strange...in order to get it to work I had to do both methods, ie in my subclass of TextArea, I set

textField.mouseWheelEnabled = false;

and I set up an listener to interrupt the bubbling of the mouse wheel event:

addEventListener(MouseEvent.MOUSE_WHEEL, disableMouseHandler, true);
...
function disableMouseHandler(event:MouseEvent):void {
event.stopPropagation();
}

It doesn't do exactly what I need it to do, as it make it so that the ScrollPane doesn't get the scroll event either, but I can either ignore it or figure out a workaround.

1 reply

slmille4AuthorCorrect answer
Inspiring
October 2, 2008
Strange...in order to get it to work I had to do both methods, ie in my subclass of TextArea, I set

textField.mouseWheelEnabled = false;

and I set up an listener to interrupt the bubbling of the mouse wheel event:

addEventListener(MouseEvent.MOUSE_WHEEL, disableMouseHandler, true);
...
function disableMouseHandler(event:MouseEvent):void {
event.stopPropagation();
}

It doesn't do exactly what I need it to do, as it make it so that the ScrollPane doesn't get the scroll event either, but I can either ignore it or figure out a workaround.