单击点击或触摸开始并同时拖动一个对象为3

时间:2013-09-18 21:12:22

标签: actionscript-3 air swipe tap

我正在创建一个可以拖动的按钮栏但是当我按下按钮后按下按钮按下按钮时,我想在拖动按钮时取消点击/点击任何建议? 谢谢

1 个答案:

答案 0 :(得分:0)

您需要根据需要删除/添加您的侦听器,或者在按钮上添加属性。类似的东西:

public class DragButton extends Sprite
{
    public var isDragging:Boolean = false;

    public function DragButton()
    {
        // add our listeners
        this.addEventListener( MouseEvent.MOUSE_DOWN, this._onMouseDown );
        this.addEventListener( MouseEvent.MOUSE_UP, this._onMouseUp );
        this.addEventListener( MouseEvent.CLICK, this._onMouseClick );
    }

    private function _onMouseDown( e:MouseEvent ):void
    {
        // add our move listener for dragging
        this.addEventListener( MouseEvent.MOUSE_MOVE, this._onMouseMove );
    }

    private function _onMouseUp( e:MouseEvent ):void
    {
        // remove our dragging listener
        this.removeEventListener( MouseEvent.MOUSE_MOVE, this._onMouseMove );
    }

    private function _onMouseMove( e:MouseEvent ):void
    {
        // drag us
        this.x = e.stageX;
        this.y = e.stageY;
        this.isDragging = true;
    }

    private function _onMouseClick( e:MouseEvent ):void
    {
        // if we're dragging, ignore
        if( this.isDragging )
        {
            this.isDragging = false;
            return;
        }

        // do our click stuff
    }
}