0
我創建了一個按鈕符號並將其導出爲Export for ActionScript
,其類名稱爲「theButton」。找出對象陣列中的按鈕位置
有一個對象,我想在myObj
構造如下創建按鈕:
public class myObj extends Sprite {
private var myBtn:theButton = new theButton();
public function myObj() {
x = Math.floor(Math.random() * 300) + 50;
y = Math.floor(Math.random() * 300) + 50;
addChild(myBtn);
}
public function getXPos():uint {
return x;
}
}
我想,當我做點擊每個按鈕像創建myObj
類和getXPos()
數組所以:
var myArray:Array = new Array();
myArray[0] = new myObj();
myArray[0].addEventListener(MouseEvent.CLICK, Clicked);
addChild(myArray[0]);
function Clicked(evt:MouseEvent):void {
var xPos1:uint = myObj(evt.target).getXPos();
trace("Position is in : " + xPos1);
}
當點擊按鈕出現在屏幕上,下面的錯誤有出現:
Type Coercion failed: cannot convert [email protected] to myObj.
請告訴我我做錯了什麼?