Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
648 views
in Technique[技术] by (71.8m points)

actionscript 3 - Flex List Scroll Speed With Mouse Wheel

I have a custom class that extends List which I am using as a container. However, the scroll speed is too fast on the mouse wheel, as in it scrolls loads even if you only move the wheel a tiny bit. I tried adding an event listener to my list for MouseEvent.MOUSE_WHEEL and setting the value of event.delta but this has had no effect. Does anyone know how I can make it slower?

My custom class is nothing special, I just created it so I could have a different itemRenders for different item types. It looks like:

public class MultipleRenderersList extends List
{
    override public function createItemRenderer(data:Object):IListItemRenderer
    {
        if (data is IRenderable)
        {
             return data.getDiaryRenderer();
        }
        else if (data is Array) 
        {
             if (data.length > 0)
             {
                  if (data[0] is IRenderable)
                  {
                       return data[0].getDiaryRenderer(data);
                  }
             }
        }
        return null;
    }
} 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The List class has a mouseWheelHandler function that you can override. Just override the function, update the delta property of the mouseevent, and call super. This example will quarter the delta, reducing the speed substantially:

package
{
  import flash.events.Event;
  import flash.events.MouseEvent;

  import mx.controls.Alert;
  import mx.controls.List;

  public class MyList extends List
  {

    override protected function mouseWheelHandler(event:MouseEvent):void {
      event.delta = event.delta/4;
      super.mouseWheelHandler(event);
    }

  }
}

However, in many cases the scroll speed / delta will be driven off of a system preference, so doing this may cause unexpected behavior for some users. The reason that adding the handler and updating the delta failed to work is that by that point mouseWheelHandler had already been called.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...