# Null object reference once in a while?

**URL:** <https://forum.kirupa.com/t/null-object-reference-once-in-a-while/314834>\
**Category:** Uncategorized\
**Created:** [October 10, 2010, 1:00am UTC](https://forum.kirupa.com/t/null-object-reference-once-in-a-while/314834 "2010-10-10T01:00:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![OMG](https://avatars.discourse-cdn.com/v4/letter/o/9dc877/32.png) [@OMG](https://forum.kirupa.com/u/OMG)\
**Post date:** [October 10, 2010, 1:00am UTC](https://forum.kirupa.com/t/null-object-reference-once-in-a-while/314834/1 "2010-10-10T01:00:18Z")

</div>

Hi

On the stage there’s an empty clip called mc1  
in the library there’s a clip called with the class name Ball  
now every frame this functions is executed:  
mc1.addChild(new Ball())

inside ball, at frame ten:  
this.parent.removeChild(this)

so this creates a bunch of balls on the stage, but after a while this error shows up:

TypeError: Error #1009: Cannot access a property or method of a null object reference.  
at Ball/frame10()

help?

Edit: ok by tracing Ball’s name I understand that even though the Ball is removed it continues to exist somewhere? Because the frames still play. Also I found out that you can check if parent is null before deleting, but I’d like to know why is this happening.
