我正在爲我的Flash應用程序(AS3和Flash CS5)開發drag'n'clone功能。克隆創建完美,但是當我嘗試拖動最近創建的克隆時,應用程序會創建一個新克隆(並允許我拖動它)。事件不會從AS3中的偵聽器中刪除
我想刪除此行爲:克隆只應拖放,不克隆。我的代碼是:
public class Car extends MovieClip
{
// imports...
public function Car()
{
addListeners();
}
private function addListeners():void
{
this.addEventListener(MouseEvent.MOUSE_DOWN,clone);
}
private function clone(e:MouseEvent):void
{
// Clone the object
var newcar = new e.target.constructor;
newcar.graphics.copyFrom(this.graphics);
newcar.x = this.x;
newcar.y = this.y;
this.parent.addChild(newcar);
newcar.addEventListener(MouseEvent.MOUSE_MOVE,dragCar);
newcar.addEventListener(MouseEvent.MOUSE_UP,dropCar);
}
private function dragCar(e:MouseEvent):void
{
e.target.startDrag();
}
private function dropCar(e:MouseEvent):void
{
e.target.stopDrag();
// This line doesn't remove the event, and I don't know why
e.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN,clone);
e.target.removeEventListener(MouseEvent.MOUSE_MOVE, dragCar);
e.target.removeEventListener(MouseEvent.MOUSE_UP,dropCar);
}
}
我希望有人能幫助我。謝謝!
因此,我正在消除事件,但它仍然存在。我該如何解決它?謝謝! –
看看我的答案的更新,我們需要參考'newcar'實例的'clone'函數作爲'newcar.clone' – danishgoel
感謝隊友,但現在我不能拖放克隆,我想做到這一點。我該怎麼做?非常感謝。 –