![]() |
![]() |
||||||
|
|||||||
| Tags: |
![]() |
|
|||
|
Hello to all, i want to make the following question:
I have a canvas which has a vertical scroll bar, inside this canvas there is a textarea control which has a vertical scroll bar too. That i want to make is: when the user put the mouse cursor on to the textarea and use the mouse wheel i want to make scrolling the canvas and not the textarea. any help will be appreciated. thanks in advance |
| Sponsored Links |
|
|||
|
You'll probably need to extend TextArea to get this to work and override
protected function mouseWheelHandler(). TextArea does an event.stopPropagation() in its version of this function. If you override the function and simply do nothing (do NOT call super.mouseWheelHandler()), that might do the trick. |
|
|||
|
You could try this:
1) Set textArea mouseChildren="false". 2) Add an eventListener to to the TextArea for its mouse wheel event when the app loads. 3) In the listener, scroll the canvas component. See attached code for a working example. Just be aware that if you do this, users will NOT be able to scroll the textArea at all. <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()" > <mx:Script> <![CDATA[ private function initApp():void{ textAreaLorem.addEventListener(MouseEvent.MOUSE_WH EEL,handleWheelEvent); } private function handleWheelEvent(event:MouseEvent):void{ var currentPosition:Number = canvasMain.verticalScrollPosition; canvasMain.verticalScrollPosition = (currentPosition - event.delta*3); } ]]> </mx:Script> <mx:Canvas id="canvasMain" x="66" y="48" width="200" height="85" verticalScrollPolicy="on" borderStyle="solid" borderColor="#FCE700"> <mx:TextArea id="textAreaLorem" x="10" y="0" height="141" verticalScrollPolicy="on" mouseChildren="false"> <mx:text><![CDATA[Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse urna ante, convallis nec, pretium quis, volutpat in, ligula. Sed quis purus. Morbi dictum consequat sapien. Maecenas at eros. Quisque venenatis felis et augue. Nullam gravida. Mauris est nunc, aliquet at, pharetra et, lobortis nec, augue. Nulla facilisi. Nullam dictum. Ut quis neque. In vitae tellus ac felis tincidunt rhoncus. Aliquam a ligula. Nullam auctor, leo at imperdiet blandit, sem metus pulvinar velit, quis vehicula metus dolor ac odio. Morbi feugiat, lorem at pellentesque tristique, arcu elit accumsan urna, vitae convallis leo orci nec nisl. Sed at est. Cras quis mi sed elit aliquam eleifend. Nulla at sapien. Donec neque turpis, congue eu, tincidunt in, luctus ut, lectus. Phasellus nibh risus, tincidunt sed, pellentesque id, tristique ut, lacus. Suspendisse augue mi, mollis in, pretium id, gravida a, quam. In arcu orci, ullamcorper vel, egestas a, convallis vitae, lacus. Sed nunc nunc, condimentum quis, molestie sed, varius a, enim. Praesent condimentum luctus velit. Ut placerat, metus in ornare lobortis, metus justo euismod odio, non ullamcorper nisl nunc tincidunt orci. Proin vehicula. Mauris aliquet, tortor molestie vulputate fermentum, ligula metus dignissim orci, sed rutrum lorem lectus ut ipsum. Vivamus eu nisl eu tortor dignissim faucibus. Nam egestas pretium massa. Sed id sapien non tellus fringilla porttitor. Nam cursus, libero nec adipiscing laoreet, leo nisl congue orci, non pellentesque dolor mi sed metus. Aliquam nibh. Morbi mollis malesuada est. Maecenas quis tellus. Aliquam tellus ligula, auctor sed, suscipit sit amet, faucibus non, pede. Nulla venenatis eleifend magna. Pellentesque in sapien. Cras lorem ipsum, vehicula eget, dictum non, porttitor bibendum, leo. Cras luctus venenatis neque. Nulla lobortis nisl sed felis. ]]></mx:text> </mx:TextArea> </mx:Canvas> </mx:Application> |
|
|||
|
Thanks for the replies. The solution to my question is this:
package { import flash.events.MouseEvent; import mx.controls.TextArea; public class newTextArea extends TextArea { public function newTextArea() { super(); } /* override protected function createChildren():void { super.createChildren(); textField.mouseWheelEnabled = false; } */ private var scrollAnterior:Number=-1; private var direccionScroll:Number=0; override protected function mouseWheelHandler(event:MouseEvent):void { var dirScroll:int = event.delta <= 0 ? 1 : -1; if (verticalScrollPosition==scrollAnterior && direccionScroll==dirScroll) return; scrollAnterior=verticalScrollPosition; direccionScroll=dirScroll; super.mouseWheelHandler(event); } } } it works fine, but now i want to make the same with the canvas, but seems is not possible override mouseWheelHandler event in it. Any help or suggestion ? Thanks in advance |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise