# Container and function

**URL:** <https://forum.kirupa.com/t/container-and-function/331367>\
**Category:** Uncategorized\
**Created:** [July 15, 2013, 6:48pm UTC](https://forum.kirupa.com/t/container-and-function/331367 "2013-07-15T18:48:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![edugaming](https://avatars.discourse-cdn.com/v4/letter/e/7993a0/32.png) [@edugaming](https://forum.kirupa.com/u/edugaming)\
**Post date:** [July 15, 2013, 6:48pm UTC](https://forum.kirupa.com/t/container-and-function/331367/1 "2013-07-15T18:48:29Z")

</div>

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

```auto

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
