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