我正在尝试创建一个 Start Drag 和 Stop Drag 简单的应用程序。但它似乎无法正常工作。它开始拖动,但它不会在任何地方放下对象
addChild(shampooing);
addChild(check_box);
check_box.gotoAndStop(2);
check_box.x = 40;
check_box.y = 550;
check_box.addEventListener(MouseEvent.MOUSE_DOWN, dragObject);
check_box.addEventListener(MouseEvent.MOUSE_UP, stopDragObject);
function dragObject(mn:MouseEvent):void
{
xPos = check_box.x;
yPos = check_box.y;
check_box.startDrag(true);
}
function stopDragObject(l:MouseEvent):void
{
if (check_box.hitTestObject(getChildByName("shampooing")))
{
check_box.x = getChildByName("shampooing").x;
check_box.y = getChildByName("shampooing").y;
}
else
{
check_box.x = xPos;
check_box.y = yPos;
}
check_box.stopDrag();
}