ランダムな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をe.target.nameに置き換えてみました。この場合、プログラムは実行されますが、アップルをクリックするとすぐに、出力ログに次のエラーが表示されます。
TypeError: Error #1034: Type Coercion failed: cannot convert "9" to flash.display.DisplayObject.
at MethodInfo-4()
それで、私がクリックしている特定のオブジェクトを削除する方法はありますか?