Question

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)

Thank you for your help,


EDIT

I've try 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 for that in my Engine.as class) :

public function removeViseur(){
            if (Engine.viseur && Engine.viseur.parent)
 {
       Engine.viseur.parent.removeChild(viseur);
        }
    }
Was it helpful?

Solution

If you want to remove viseur in Engine, try this

  if (Engine.viseur && Engine.viseur.parent)
 {
       Engine.viseur.parent.removeChild(viseur);
  }

Or put this code in a function in Engine, and call the function in backToJardin.

EDIT

The function in engine should be static.

public static function removeViseur()
{

    if (viseur && viseur.parent)
    {
        viseur.parent.removeChild(viseur);
    }
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top