我正在为我的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
感谢队友,但现在我不能拖放克隆,我想做到这一点。我该怎么做?非常感谢。 –