Copy link to clipboard
Copied
I've got a problem that I can't figure out.
I've got in my Engine Class (engine.as) this :
public static var viseur:Viseur;
var lookCocoDessous:Boolean = thisBack == "cocotierDessous";
if (lookCocoDessous) {
viseur = new Viseur(stage);
stage.addChild(viseur);
viseur.visible = true;
souris.visible = false;
puzzle.addListeners(); }
And in my puzzle class (Puzzle.as) this :
public static var viseur:Viseur;
and when the function "backToJardin" is called I want to remove "viseur" (which has been called in the Engine.as). So I wrote this :
public function backToJardin(thisBack:String😞void{
Engine.viseur.stage.removeChild(viseur);
Engine.newBack = "jardin";
stageRef.dispatchEvent(new Event("changeBackground")); }
But I've got this error :
TypeError: Error #2007: Parameter child must be non-null. at flash.display::DisplayObjectContainer/removeChild() at com.laserdragonuniversity.alpaca::Puzzle/backToJardin()
Do you know why ? And how can I resolve it ?
I'd like to remove COMPLETELY "viseur" when the function is called in my Puzzle.as (it will never be called again, so I want to "destroy" it)
I've tried to put
Engine.removeViseur();
in my backToJardin function
and put
public function removeViseur(){
stage.removeChild(viseur);}
in my Engine class, but I've got this error : error 1061 removeViseur can not be defined through a reference with static type
(and same thing if I put that in my Engine.as class) :
public function removeViseur(){
if (Engine.viseur && Engine.viseur.parent) {
Engine.viseur.parent.removeChild(viseur); }
}
Copy link to clipboard
Copied
viseur has already been removed.
you can always use:
if(viseur&&viseur.stage){
viseur.parent.removeChild(viseur);
}