Actionscript MouseScroll / MouseDrag

时间:2015-07-21 07:25:53

标签: events scroll actionscript click drag

是否有" MouseScroll"或者" MouseDrag"在Actionscript中的事件,我找不到合适的东西。 我有这个:

resultPumpVolCalcBoxQv.addEventListener(MouseEvent.CLICK, getPumpVolumenQv);
resultPumpVolCalcBoxQn.addEventListener(MouseEvent.CLICK, getPumpVolumenn);
resultPumpVolCalcBoxQvng.addEventListener(MouseEvent.CLICK, getPumpVolumenng);

function getPumpVolumenQv(e:MouseEvent):void {

     pumpeVolQv = Number(pumpeVolumenstromTextFieldqv.text);
     pumpeVolN  = Number(pumpeVolumenstromTextFieldn.text);
     pumpeVolNg = Number(pumpeVolumenstromTextFieldng.text);
     if(pumpeVolumenstromTextFieldng.text != null && pumpeVolumenstromTextFieldn.text != null) {        
        totalqv = (pumpeVolNg * pumpeVolN)/1000
        pumpeVolumenstromTextFieldqv.text = " " + totalqv;
     } else {
         //
     }   
}

目前,这适用于点击事件。 如果我拖动类似滚动条的东西,我想让这个计算发生。

2 个答案:

答案 0 :(得分:1)

您必须结合使用MouseDown和MouseOut来创建拖动结果

obj.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
obj.addEventListener(MouseEvent.MOUSE_UP, mouseUp);

function mouseDown($e:MouseEvent):void{
MovieClip($e.currentTarget).startDrag();
}

function mouseUp($e:MouseEvent):void{
MovieClip($.currentTarget).stopDrag();
}

如果要将其约束到X或Y位置,请在startDrag()函数中添加矩形框参数

答案 1 :(得分:1)

您必须使用鼠标向上和鼠标按下事件才能实现此目的。但是,在不需要时,请小心添加然后删除事件侦听器。这样,您将确保正确删除事件侦听器,而不是多次添加,从而导致内存问题。

private var yourObject:MovieClip;

private function addDragListeners():void
{
    yourObject.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown, false, 0, true);
    yourObject.addEventListener(MouseEvent.MOUSE_DOWN, onMouseUp, false, 0, true);
}

private function removeDragListeners():void
{
    yourObject.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    yourObject.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseUp);
}

protected function onMouseDown(e:MouseEvent):void
{
    yourObject.startDrag();
}

protected function onMouseUp(e:MouseEvent):void
{
    yourObject.stopDrag();
}

如果需要为拖动添加一些边界,可以查看startDrag()方法。