我有一个可以使用 startDrag() 和 stopDrag() 在舞台上移动的 MovieClip 实例。该实例还有一些使用 addChild() 的子 MovieClip。拖动时,父级移动子级,这很好。孩子们有自己的 startDrag() 和 stopDrag() 应该只适用于孩子对象,但它也会移动父母和其他孩子。单击子项时,将调用子项的 MouseEvent,但父项也是如此。
public class Component extends MovieClip {
private var nodes_array:Array = new Array();
public function Component() {
x = 60;
y = 100;
nodes_array.push(addChild(new Node(50, 50)));
nodes_array.push(addChild(new Node(150, 150)));
addEventListener(MouseEvent.MOUSE_DOWN, startDraggingComponent);
addEventListener(MouseEvent.MOUSE_UP, stopDraggingComponent);
}
private function startDraggingComponent(me:MouseEvent):void {
this.startDrag();
}
private function stopDraggingComponent(me:MouseEvent):void {
this.stopDrag();
}
public class Node extends MovieClip {
public function Node(x:int, y:int) {
this.x = x;
this.y = y;
addEventListener(MouseEvent.MOUSE_DOWN, startDraggingNode);
addEventListener(MouseEvent.MOUSE_UP, stopDraggingNode);
}
private function startDraggingNode(me:MouseEvent):void {
this.startDrag();
}
private function stopDraggingNode(me:MouseEvent):void {
this.stopDrag();
}