Hello, fellow Newgrounders. I was hoping someone would be able to help me with a current issue in my game development.
So, basically, I have two classes. NPC and Player. NPC is a generic class that holds functions that in-game players and enemies can both use, but for player and AI-controlled purposes, can allow me to make seperate classes. First, a little bit of code for example:
public class NPC extends MovieClip
{
public function NPC():void
{
trace("NPC::NPC()");
init();
}
public function init():void
{
trace("NPC::init()");
}
public function main():void
{
}
}
public class Player extends MovieClip
{
public function Player():void
{
trace("Player::Player()");
init();
}
override public function init():void
{
trace("Player::init()");
}
override public function main():void
{
}
}
A little bit of explanation. The init() function sets up any variables and settings for the class when it is first created, while the main() function is run every frame in a root EnterFrame listener. The Player class is supposed to override the init() and main() functions from the NPC class.
The trace() functions are there just to demonstrate what scope and what function is being called. My main "Player" movieclip is linked to the Player class and sub-class NPC. The player is created as an object in my Document class and is handled there as such.
Anyways, my problem is that the NPC (parent) class constructor is being called, which then calls the init() function. The Player (child) class constructor is not called at all upon declaration. Any thoughts?
tl;dr child class constructor isn't called but the parent class constructor is. I just gave some code examples and explanations for further insight.
I really do appreciate any help or comments you guys can leave. Thanks for anything/everything!
Mike