如何使用ActionScript 3拖放特定区域中的对象,以及如何使用热门乐趣。
答案 0 :(得分:1)
有几种方法可以做到这一点。最简单的方法是使用Sprite.startDrag()
方法。
来自the Adobe docs,这是一个例子:
import flash.display.Sprite;
import flash.events.MouseEvent;
var circle:Sprite = new Sprite();
circle.graphics.beginFill(0xFFCC00);
circle.graphics.drawCircle(0, 0, 40);
var target1:Sprite = new Sprite();
target1.graphics.beginFill(0xCCFF00);
target1.graphics.drawRect(0, 0, 100, 100);
target1.name = "target1";
var target2:Sprite = new Sprite();
target2.graphics.beginFill(0xCCFF00);
target2.graphics.drawRect(0, 200, 100, 100);
target2.name = "target2";
addChild(target1);
addChild(target2);
addChild(circle);
circle.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown)
function mouseDown(event:MouseEvent):void {
circle.startDrag();
}
circle.addEventListener(MouseEvent.MOUSE_UP, mouseReleased);
function mouseReleased(event:MouseEvent):void {
circle.stopDrag();
trace(circle.dropTarget.name);
}
根据您的需要修改它;您可以在释放鼠标时检查对象是否为指定区域。