Proper way to extend a class in Haxe?

I have a class that I am initializing like so:

class Game extends Sprite{
    public function new(_img,_img2,_numplayers){

From this class I am initializing another class and extending

aiPlayer = new Ai(img, img2, numPlayers);

the Ai class looks like this:

class Ai extends Game{

	public function new(img,img2,numplayers){

When tracing out the output I notice the output keeps running in a loop. Is it supposed to do that? Or am I not extending the class properly?

If you call “aiPlayer = new Ai(img, img2, numPlayers);” in/through the constructor of Game, or any kind of "new Ai()…, it will loop.
Else it looks ok.

(As a side note, having the “Ai” extending a “Game” doesnt sound “right”, if you need to access Game in Ai, just pass the game object to Ai, or make it static)

Not calling it in the constructor. I don’t see it duplicating data but it the trace is keeps looping the output of some of the other functions in the class.

Do you have a function call in the Game constructor which indirectly calls new Ai()?
Else “minify” your game constructor(closing bracket after super) and see what happens.

First of all I want to thank you for the help. Second… I am not familiar on how to ‘minify’.

I am not calling it directly in the constructor but it is in the chain of the functions that are called when the game class is called. The Ai class is being called about two levels deep. I guess you could say the constructor is calling it ‘directly’. What I have noticed though is that while the trace is behaving as if it’s in a loop it does not trace out continuously. There is a delay before it traces out the output again. Does that make sense?

What i ment was to close the Game constructor directly after the super(); call.
You would see it wouldnt loop then anymore.

The moment you call “new AI()” somehow through the Game constructor, be it directly in it, or through other functions/classes which you call/create in it - it will loop.

To get a Game-object, the whole constructor needs to run/finish, with all the function/class calls inside.
In the moment there is a “new Ai” call involved, it loops because to create a AI-object the AI and Game constructor need to run.

Why does Ai need to extend Game?

Ah I see what you are saying. I can call Ai after I have set up game variables. I don’t have to create them during the new(){ super() }

Thanks for the pointer.