【问题标题】:Can I track drag event?我可以跟踪拖动事件吗?
【发布时间】:2014-01-22 01:23:27
【问题描述】:

我想在某些 UIComponent 上调用 startDrag,然后在每次拖动组件的位置发生变化时接收事件。这可能吗?我还没有发现任何可能性。

【问题讨论】:

  • 也许检查鼠标移动处理程序中是否有东西被拖动。

标签: actionscript-3 flash apache-flex actionscript flex4


【解决方案1】:

我认为您可能想要使用 MouseDown、MouseMove 和 MouseUp。

var myUIComponent
var isDown:Boolean = false;
var startX:Number = 0;
var startY:Number = 0;

myUIComponent.addEventListener(MouseEvent.MOUSE_DOWN, down);

function down(e:MouseEvent){
    startX = e.stageX;
    startY = e.stageY;
    isDown = true;
    stage.addEventListener(MouseEvent.MOUSE_MOVE,moving);
    stage.addEventListener(MouseEvent.MOUSE_UP, up);
}

function moving(e:MouseEvent)
{
    if (isDown){
        var distanceX = startX - e.stageX;
        var distanceY = startY - e.stageY;
        // Do something
    }
}

function up(e:MouseEvent)
{
    stage.removeEventListener(MouseEvent.MOUSE_MOVE,moving);
    stage.removeEventListener(MouseEvent.MOUSE_UP, up);
    isDown = false;
}

【讨论】:

    猜你喜欢
    • 2012-03-23
    • 1970-01-01
    • 2010-11-23
    • 2018-02-22
    • 2010-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多