2009-12-30 70 views
0

我有一个VBox包含一堆面板。我已经实现了拖放功能,但是当物品靠近边缘时,我需要能够自动滚动。我有不同的结果。我可以让它工作,但不好。我的例子如下。如果用户在靠近顶部或底部边缘的地方稍微弹一下鼠标,它就会起作用,但如果他们只是在那里握住鼠标,我希望它能够工作。有什么建议么?当物品靠近顶部或底部边缘时,如何自动滚动VBox?

在鼠标按下(我做其他一些事情,但是这是其中之一):

VBox(di.parent).addEventListener(MouseEvent.MOUSE_MOVE,autoScrollSection,true,500); 

上的DragDrop

VBox(evt.currentTarget.parent).removeEventListener(MouseEvent.MOUSE_MOVE, autoScrollSection,true); 

这里是自动滚动功能:

private function autoScrollSection(evt:MouseEvent):void{ 
    var tempVBox:VBox = VBox(evt.currentTarget); 
    if(tempVBox.mouseY<50){ 
     tempVBox.verticalScrollPosition += -50; 
    } 
    if(tempVBox.mouseY> int(tempVBox.height-50)){ 
     tempVBox.verticalScrollPosition += +50; 
    } 
} 

所以,如果他们在50px的边缘内,那么它应该滚动50px。为了得到一个影响,我夸大了数字。

回答

1

我继承人如何解决它:

[Bindable] public var timer:Timer = new Timer(50); 
private function autoScrollSection(active:Boolean,cont:VBox):void{ 
    if(active){ 
     timer.addEventListener(TimerEvent.TIMER,function():void{ 
      if(cont.mouseY<50){ 
       cont.verticalScrollPosition += -20; 
      } 
      if(cont.mouseY> int(cont.height-50)){ 
       cont.verticalScrollPosition += +20; 
      } 
     }) 
     timer.start(); 
    }else{ 
     timer.stop(); 
    } 
} 

然后分别

autoScrollSection(true,VBox(di.parent)); 
autoScrollSection(false,VBox(evt.currentTarget.parent)); 

它的工作原理,但感觉就像一个黑客位的改变在按下鼠标和拖放调用了这一点。我欢迎任何更好的建议。

相关问题