1
저는 startDrag() 및 stopDrag()를 사용하여 스테이지 주위를 이동할 수있는 MovieClip 인스턴스가 있습니다. 인스턴스에는 addChild()를 사용하는 일부 자식 MovieClip도 있습니다. 드래그 할 때 부모는 아이들을 움직입니다. 자식 객체에는 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();
}