So, I have this Player.as class file with the following code:
private function PressAKey(event:KeyboardEvent):void
{
getDistance();
if(event.keyCode == 32 && placedBomb == false && bombNumber == 0)//space
{
xKey = true;
placeBomb();
placedBomb = true;
}
}
Using this in conjunction with the following placeBomb() function:
private function placeBomb():void{
MainClass.container.addChildAt(bomb,0);
bomb.x = this.x;
bomb.y = this.y+20;
bombNumber ++;
}
The problem comes from this function which is trying to calculate the distance between the player and the bomb so that I can start building interactions:
private function getDistance():void{
distance = Math.sqrt( ( this.x - MainClass.container.bomb.x ) * ( this.x - MainClass.container.bomb.x ) + ( this.y - MainClass.container.bomb.y ) * ( this.y - MainClass.container.bomb.y ) );
trace(distance);
}
I get this error when I try this:
TypeError: Error #1010: A term is undefined and has no properties.
at Player/getDistance()
at Player/PressAKey()
Do you have any idea what I’m missing? It’s definitely a scoping issue, so what would I need to include in order for the entire class to recognize the bomb?
bombis no property ofMainClass.container.bombis a only child.refer a following code.
How to reference all the children.