I've created a Button symbol and export it Export for ActionScript with class name "theButton".
There is an object and i would like to create that Button in myObj constructor as below :
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;
}
}
I'm trying to create an array of myObj class and getXPos() when i do clicking on each button like so :
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);
}
When clicking on the buttons appears on the screen, following error has comes up:
Type Coercion failed: cannot convert theButton@2c9dcf99 to myObj.
Please tell me what am i doing wrong ?