我想在某个UIComponent上调用startDrag
,然后每次拖动组件的位置发生变化时都会收到事件。这可能吗?我还没有发现任何可能性。
答案 0 :(得分: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;
}