1
我已经在随机x和y的舞台上添加了一个movieclip(一个苹果的简单图像)的几个实例。现在我试图点击每一个删除它们。如何在Flash AS3中点击舞台上的特定符号?
以下是我有:
public function Apples() {
for(var count:int=1; count<=10; count++){
var apple = new Apple();
apple.x = Math.random() * stage.stageWidth;
apple.y = Math.random() * stage.stageHeight;
apple.name = count;
stage.addChild(apple);
}
stage.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void{
stage.removeChild(e.target);
}
}
我碰到下面的错误,如果我试图编译:
1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject.
我自己也尝试了e.target代e.target.name。在这种情况下,程序运行,但只要我点击了苹果,我得到的输出日志以下错误:
TypeError: Error #1034: Type Coercion failed: cannot convert "9" to flash.display.DisplayObject.
at MethodInfo-4()
那么,有没有办法去掉,我点击特定对象?
这有帮助,谢谢:) –
IMO弱听者是初学者的双刃剑。它们让事情变得更加简单,当你了解事情的工作方式时,这并不总是一件好事。 – Pier