Copy link to clipboard
Copied
Hi, this is probably an easy question for someone who is in the know, but anyway I'm trying to communicate between 2 different classes using a getter in a class, but when I call the getter to get a value I get an error. Heres the code-
//THE PLAYER CLASS
public function get _playerX():Number
{
return this.x;
}
public function get _playerY():Number
{
return this.y;
}
//ENEMY CLASS
private function EnemyAi(){
thePlayerX = Player._playerX;
thePlayerY = Player._playerY;
}
I get this error:
1119: Access of possibly undefined property _playerX through a reference with static type Class.
Copy link to clipboard
Copied
Looks to me like flash thinks you're trying to access a static Player class property rather than the property of the Player instance you've instantiated...
I presume you have a Main class that creates instance of these child classes?
You need to pass a reference to the Player class into the Enemy constructor and use that reference to get the property you are after. Does that make sense?
Copy link to clipboard
Copied
sort of, how do I do that exactly, thanks
Copy link to clipboard
Copied
thanks I figured out how to do it.