Glad Marty's solution worked for you, although it is not too efficient (that MouseEvent.MOUSE_MOVE listener is a killer). The problem with your original code was that the rectangle in which you limit the dragging boundaries must be relative to the parent's coordinates. Also, depending on where you have the registration point of your square, you might have to take its width into account, if you don't want any part of it to move out of the stage.
For example, if your red square is directly on the stage, its registration point is located on its centre, and you want to limit the dragging to the whole x-axis of the stage, this will work:
e.currentTarget.startDrag(
false,
new Rectangle(
e.currentTarget.width/2,
e.currentTarget.y,
stage.stageWidth-e.currentTarget.width,
0
)
);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…