# Need to remove a sprite object when another sprite object hits it

**URL:** <https://forum.kirupa.com/t/need-to-remove-a-sprite-object-when-another-sprite-object-hits-it/320455>\
**Category:** flash\
**Created:** [March 24, 2011, 5:26am UTC](https://forum.kirupa.com/t/need-to-remove-a-sprite-object-when-another-sprite-object-hits-it/320455 "2011-03-24T05:26:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![iceherosubzero](https://avatars.discourse-cdn.com/v4/letter/i/8797f3/32.png) [@iceherosubzero](https://forum.kirupa.com/u/iceherosubzero)\
**Post date:** [March 24, 2011, 5:26am UTC](https://forum.kirupa.com/t/need-to-remove-a-sprite-object-when-another-sprite-object-hits-it/320455/1 "2011-03-24T05:26:34Z")

</div>

Hello All,

I have a **brick class** where I have created a rectangle using _flash.display.graphics._  
I am using this **brick class** to create a grid of 10 X 10 in another class called _grid_ using **new brick()** in a _for loop_.  
I have another **class called ball** where I have created a circle with _flash.display.graphics._

The problem is that I want to remove / destroy individual bricks when the ball hits the bricks on Event.ENTER\_FRAME which is not happening.

the error I get is shown only for the last brick that is created in a for loop.

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.  
at flash.display::DisplayObjectContainer/removeChild()  
at grid/ball\_movement()// my function in enter frame event

The code I wrote in ENTER\_FRAME is

if (Ball.hitTestObject(bricks)) {  
removeChild(bricks);  
}

where  
var Ball:ball=new ball()  
var bricks:brick=new brick()

any help is highly appreciated.  
thanks  
iceheros 🙂
