1
我有一個MovieClip實例,可以使用startDrag()和stopDrag()在舞臺上移動。該實例還有一些使用addChild()的小孩影片剪輯。父母在拖動時移動孩子,這很好。孩子們有自己的startDrag()和stopDrag(),它們只應用於子對象,但它也會移動父對象和其他子對象。當點擊一個孩子時,孩子的MouseEvent被調用,但父母也是如此。AS3 - 孩子使用startDrag移動父親
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();
}