我在舞台上随机 x 和 y 添加了一些影片剪辑(一个简单的苹果图像)实例。现在我试图点击每一个来删除它们。
这是我所拥有的:
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.name 代替 e.target。在这种情况下,程序会运行,但只要我点击苹果,就会在输出日志中收到以下错误:
TypeError: Error #1034: Type Coercion failed: cannot convert "9" to flash.display.DisplayObject.
at MethodInfo-4()
那么有什么方法可以删除我点击的特定对象吗?