Pergunta

I want to call startDrag on some UIComponent and then receive event each time position of dragged component changed. Is this possible? I haven't found any possibility yet.

Foi útil?

Solução

I think you might be wanting to use a MouseDown,MouseMove, and 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;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top