Question

I've got a little problem.

I'm trying to remove a child called in an other class.

I've called "viseur" in my Engine class like that :

private var viseur:Viseur;
viseur = new Viseur(stage);
stage.addChild(viseur);

Now, in my Puzzle.as class I'd like to removeChild(viseur) when my puzzle is complete. How do I do to do that ?

I've tried :

Engine.viseur.stage.removeChild(viseur);

But it is not working... (and either Engine.viseur.removeChild(viseur) )

Anyone know how could I do that ?

Thank you very much,

Was it helpful?

Solution

There are two issues at play here:

  1. The call Engine.viseur.stage.removeChild(viseur); does not work because the variableviseur is private to the Engine class. If you wish for it to be accessible to other classes, you need to make it public.
  2. However, the other issue with this is that the viseur variable is not a static variable either. So accessing it like this, Engine.viseur.stage.removeChild(viseur); is still incorrect even if you fix the variable to be public. if you wish to access it via another class, you can either 1) pass a reference of the instance of the Engine class to your other class so that it can access the viseur variable or 2) make the viseur variable a static variable, but remember if you do this, that means you can only ever have one Viseur object named viseur.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top