Container and function

hi there,

i have problems fixing that code… maybe someone could help me. it worked really well before i did this container/sprite thing… now i always get error messages because of null or wrong parent


if (AKeyIsDown)
 {
    var Container:Sprite = new Sprite();
    //Container.addChild(Laser);
    addChild(Container);
   
    var Laser:Shape = new Shape();

    Laser.graphics.lineStyle(2, 0xff0000);
    Laser.graphics.moveTo(Player_mc.x, Player_mc.y);
    Laser.graphics.lineTo(XYZ.x, XYZ.y);
   
    Container.addChild(Laser);

 }else     
 {
    if (NoKeyIsDown)
    {
      trace("nooooookeydown")
      Container.removeChild(Laser);
      Laser.graphics.clear();
    }

 }

please help