jesterxl

Scroller.as mouse wheel scrolling

Jan 23rd, 2012
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private function skin_mouseWheelHandler(event:MouseEvent):void
  2.     {
  3.         const vp:IViewport = viewport;
  4.         if (event.isDefaultPrevented() || !vp || !vp.visible)
  5.             return;
  6.            
  7.         // Dispatch the "mouseWheelChanging" event. If preventDefault() is called
  8.         // on this event, the event will be cancelled.  Otherwise if  the delta
  9.         // is modified the new value will be used.
  10.         var changingEvent:FlexMouseEvent = MouseEventUtil.createMouseWheelChangingEvent(event);
  11.         if (!dispatchEvent(changingEvent))
  12.         {
  13.             event.preventDefault();
  14.             return;
  15.         }
  16.        
  17.         const delta:int = changingEvent.delta;
  18.        
  19.         var nSteps:uint = Math.abs(event.delta);
  20.         var navigationUnit:uint;
  21.  
  22.         // Scroll delta "steps".  If the VSB is up, scroll vertically,
  23.         // if -only- the HSB is up then scroll horizontally.
  24.          
  25.         // TODO: The problem is that viewport.validateNow() doesn’t necessarily
  26.         // finish the job, see http://bugs.adobe.com/jira/browse/SDK-25740.  
  27.         // Since some imprecision in mouse-wheel scrolling is tolerable this is
  28.         // ok for now.  For 4.next we should add Scroller API for (reliably)
  29.         // scrolling in different increments and refactor code like this to
  30.         // depend on it.  Also applies to VScroller and HScroller mouse
  31.         // handlers.
  32.        
  33.         if (verticalScrollBar && verticalScrollBar.visible)
  34.         {
  35.             navigationUnit = (delta < 0) ? NavigationUnit.DOWN : NavigationUnit.UP;
  36.             for (var vStep:int = 0; vStep < nSteps; vStep++)
  37.             {
  38.                 var vspDelta:Number = vp.getVerticalScrollPositionDelta(navigationUnit);
  39.                 if (!isNaN(vspDelta))
  40.                 {
  41.                     vp.verticalScrollPosition += vspDelta;
  42.                     if (vp is IInvalidating)
  43.                         IInvalidating(vp).validateNow();
  44.                 }
  45.             }
  46.             event.preventDefault();
  47.         }
  48.         else if (horizontalScrollBar && horizontalScrollBar.visible)
  49.         {
  50.             navigationUnit = (delta < 0) ? NavigationUnit.RIGHT : NavigationUnit.LEFT;
  51.             for (var hStep:int = 0; hStep < nSteps; hStep++)
  52.             {
  53.                 var hspDelta:Number = vp.getHorizontalScrollPositionDelta(navigationUnit);
  54.                 if (!isNaN(hspDelta))
  55.                 {
  56.                     vp.horizontalScrollPosition += hspDelta;
  57.                     if (vp is IInvalidating)
  58.                         IInvalidating(vp).validateNow();
  59.                 }
  60.             }
  61.             event.preventDefault();
  62.         }            
  63.     }
Advertisement
Add Comment
Please, Sign In to add comment