# Creating a close function, not sure why its not working

**URL:** <https://forum.kirupa.com/t/creating-a-close-function-not-sure-why-its-not-working/266161>\
**Category:** flash\
**Created:** [July 16, 2008, 9:35pm UTC](https://forum.kirupa.com/t/creating-a-close-function-not-sure-why-its-not-working/266161 "2008-07-16T21:35:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![saxx](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@saxx](https://forum.kirupa.com/u/saxx)\
**Post date:** [July 16, 2008, 9:35pm UTC](https://forum.kirupa.com/t/creating-a-close-function-not-sure-why-its-not-working/266161/1 "2008-07-16T21:35:32Z")

</div>

Ok posting one last thing today.  
I’m creating a close function, basically it removes the display box, and the text, if it detects its not null. Though when i remove any text other than the text1 I’m getting a null object error.

heres the code

```auto

function exit(event:MouseEvent):void

{
    removeChild(mc_x)
    removeChild(dpBox)
    timer1.stop()
    timer2.stop()
    timer3.stop()
    
    
    {
    if(text1 != null)
    {
                text1.parent.removeChild(text1)

    }
    else if(text2 != null)
    {
                text2.parent.removeChild(text2)

    }
    else if(text3 != null)
            {
                text3.parent.removeChild(text3)

            }
            
                                else
                                {
                                }

            
    }
            

    

}

```
