Prevent the Flex TextArea from intercepting the mouse wheel event
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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.
January 10th, 2009 - 08:46
You’re the man. This is exactly what I needed.
April 3rd, 2009 - 13:41
Another method: addEventListener with higher priority then stopImmediatePropagation !
April 19th, 2009 - 17:25
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.
April 30th, 2009 - 21:28
It works in FP as well. Thanks for the post. Big help!
July 15th, 2009 - 21:05
Thanks for the solution. Great help.
July 23rd, 2009 - 06:39
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!
July 30th, 2009 - 11:29
I had the same problem. The following solution seems to work to:
##################################
< ![CDATA[
public function setScroll(event:Event):void{
event.target.verticalScrollPosition=0;
}
]]>
July 30th, 2009 - 11:31
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;
}
September 3rd, 2009 - 13:18
Bailed me out after some disappointing research.
Thanks.
September 8th, 2009 - 23:23
Thanks. I had to add
import flash.events.MouseEvent;
September 15th, 2009 - 23:14
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
January 5th, 2010 - 19:49
very good, thank you!
had to add an import statement for the mouse event in Flex
May 6th, 2010 - 07:37
You rock! this is what I needed. Thanks.
September 22nd, 2010 - 10:54
Very big thanks for this.
September 23rd, 2010 - 19:51
Thank you so much. It works like charm!
November 26th, 2010 - 12:47
Any reason you didn’t just change it to use an.
That’s what I did and it scrolls perefectly!
November 26th, 2010 - 12:49
Oops, forgot to escape the tags!
I meant change it to an mx:Text
June 14th, 2011 - 10:17
Oh great…!!!
I had the EXACT same issue you faced and applying your solution has solved my issue the way it did for your.
Thanks a lot…
And yes, I also believe in your strategy of ‘rolling on our own’
Keep it up…..