Prevent the Flex TextArea from intercepting the mouse wheel event
Posted 9 Dec 2008 by Akinwale Ariwodola
Life has just taught me a lesson. Do not encounter problems that people have rarely experienced.

I have a story to tell. I had a TextArea in a VBox which prevented the container from vertically scrolling if the mouse cursor was over the TextArea. The vertical scrolling worked fine when the mouse cursor was over other parts of the container. After spending several hours on Google looking for how to fix this and coming across only a couple of solutions (this and this) which did not work, or maybe my Google fu just plain sucks, I decided to roll my own.

After doing a bit of digging, following the approach in the second solution, I discovered that the TextArea has a mouseWheelHandler event handler defined. All I had to do was remove the event listener like so:
package
{

import mx.controls.TextArea;

public class MultilineText extends TextArea
{
override protected function createChildren():void
{
super.createChildren();
removeEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler);
}
}

}

Problem Solved. This occurred in an AIR app, though. I haven't bothered to test this in Flash Player and I really don't feel like it. Hopefully, this helps someone who encounters something like this in the future.

Comments (12)

Posted 10 Jan 2009 8:46am by Bryan Bartow
You're the man. This is exactly what I needed.
Posted 03 Apr 2009 1:41pm by tom
Another method: addEventListener with higher priority then stopImmediatePropagation !
Posted 19 Apr 2009 5:25pm by borf
Wow, thanks a ton you saved my skin. It drives me nuts how so much of the Flex SDK does bizzare things like this that are by zero means "easy" to figure out.
Posted 30 Apr 2009 9:28pm by Don O'Brien
It works in FP as well. Thanks for the post. Big help!
Posted 15 Jul 2009 9:05pm by Travis
Thanks for the solution. Great help.
Posted 23 Jul 2009 6:39am by Daan
Tryed it out in a Vbox with a mousewheel listener (Flex 3.2) that contains different textareas. Didnt work with the solution you provided So I tryed the "textField.mouseWheelEnabled = false;" which ended the scrolling but I still couldnt scroll in my Vbox because the textareas in it where still listening to the wheel-event. So I added your removeListener line and it did the job!
Posted 30 Jul 2009 11:29am by oliver merx
I had the same problem. The following solution seems to work to:

scroll="setScroll(event);"
/>

##################################


public function setScroll(event:Event):void{
event.target.verticalScrollPosition=0;
}
]]>

Posted 30 Jul 2009 11:31am by oliver merx
ups: it seems that I cannot post tags ...

Put this into the TextArea attributes

###################
scroll="setScroll(event);"
###################

public function setScroll(event:Event):void{
event.target.verticalScrollPosition=0;
}
Posted 03 Sep 2009 1:18pm by Scott Smith
Bailed me out after some disappointing research.

Thanks.
Posted 08 Sep 2009 11:23pm by Andrew
Thanks. I had to add

import flash.events.MouseEvent;
Posted 15 Sep 2009 11:14pm by Trevor
Thanks a million for this.

I had the same problem and had to word it a few different ways to Google search to find this solution. It's been a big help.


- Trevor
Posted 05 Jan 2010 7:49pm by mac
very good, thank you!
had to add an import statement for the mouse event in Flex

Post A Comment

Please enter the characters as they appear in the image
Captcha