Antinormal

9Dec/0818

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.

Comments (18) Trackbacks (0)
  1. You’re the man. This is exactly what I needed.

  2. Another method: addEventListener with higher priority then stopImmediatePropagation !

  3. 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.

  4. It works in FP as well. Thanks for the post. Big help!

  5. Thanks for the solution. Great help.

  6. 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!

  7. I had the same problem. The following solution seems to work to:

    />

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


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

  8. 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;
    }

  9. Bailed me out after some disappointing research.

    Thanks.

  10. Thanks. I had to add

    import flash.events.MouseEvent;

  11. 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

  12. very good, thank you!
    had to add an import statement for the mouse event in Flex

  13. You rock! this is what I needed. Thanks.

  14. Very big thanks for this.

  15. Thank you so much. It works like charm!

  16. Any reason you didn’t just change it to use an .

    That’s what I did and it scrolls perefectly!

  17. Oops, forgot to escape the tags!

    I meant change it to an mx:Text

  18. 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…..


Leave a comment

(required)

 

No trackbacks yet.