Question
super and Polymorphism
I have a class called Player and a subclass that extends
player called CompPlayer. Here is my code for the player class
(only that which relates to this topic):
class Player
{
//Class properties
//Private Members
private var m_PicFile:String;
//Class Methods
public function Player(picFile:String)
{
this.m_PicFile = picFile;
}
public function getPicName():String
{
trace("HERE I AM");
return this.m_PicFile;
}
}
The CompPlayer class looks like:
class CompPlayer extends Player
{
//Class properties
//Private Members
private var m_PlayStyle:Number;
//Class Methods
public function CompPlayer(picFile:String, playStyle:Number)
{
super(picFile, name, age, gender);
this.m_PlayStyle = playStyle;
}
public function getPicName()
{
super.getPicName();
}
}
I then instantiate a CompPlayer:
var comp:CompPlayer = new CompPlayer("picture.png", 2);
I then run the following code:
comp.getPicName();
In the debug screen, I get "HERE I AM" and "undefined". This is the problem. It calls the correct method, but cannot access the variable. If I delete the getPicName() inside of the CompPlayer class, it works just fine and outputs "HERE I AM" and "picture.png". Anybody know what is going on here? Why can't I access the m_PicFileName using the super.getPicName() from the CompPlayer class?
class Player
{
//Class properties
//Private Members
private var m_PicFile:String;
//Class Methods
public function Player(picFile:String)
{
this.m_PicFile = picFile;
}
public function getPicName():String
{
trace("HERE I AM");
return this.m_PicFile;
}
}
The CompPlayer class looks like:
class CompPlayer extends Player
{
//Class properties
//Private Members
private var m_PlayStyle:Number;
//Class Methods
public function CompPlayer(picFile:String, playStyle:Number)
{
super(picFile, name, age, gender);
this.m_PlayStyle = playStyle;
}
public function getPicName()
{
super.getPicName();
}
}
I then instantiate a CompPlayer:
var comp:CompPlayer = new CompPlayer("picture.png", 2);
I then run the following code:
comp.getPicName();
In the debug screen, I get "HERE I AM" and "undefined". This is the problem. It calls the correct method, but cannot access the variable. If I delete the getPicName() inside of the CompPlayer class, it works just fine and outputs "HERE I AM" and "picture.png". Anybody know what is going on here? Why can't I access the m_PicFileName using the super.getPicName() from the CompPlayer class?