# removeChild

**URL:** <https://forum.kirupa.com/t/removechild/261319>\
**Category:** flash\
**Created:** [May 26, 2008, 11:33am UTC](https://forum.kirupa.com/t/removechild/261319 "2008-05-26T11:33:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RebuiltJorge](https://avatars.discourse-cdn.com/v4/letter/r/94ad74/32.png) [@RebuiltJorge](https://forum.kirupa.com/u/RebuiltJorge)\
**Post date:** [May 26, 2008, 11:33am UTC](https://forum.kirupa.com/t/removechild/261319/1 "2008-05-26T11:33:33Z")

</div>

Wow, this question is so basic, I almost don’t want to ask it. I have an object I place in a container, when the container hits my ship, I want to remove the object, however I get the message  
display object must be the child of the caller, please see code:

//DISPLAY BLACK HOLE ICON  
ActionScript Code:  
[LEFT][COLOR=#0000FF]public[/COLOR] [COLOR=#000000] **function** [/COLOR] displayBlackHoleIconCOLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]  
myBlackHoleIconContainer = [COLOR=#000000] **new** [/COLOR] SpriteCOLOR=#000000[/COLOR]  
myBlackHoleIconContainer.[COLOR=#000080]x[/COLOR] = randomXCOLOR=#000000[/COLOR];

```
        [COLOR=#0000FF]for[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000] **var** [/COLOR] i:[COLOR=#0000FF]int[/COLOR] = [COLOR=#000080]0[/COLOR]; i &lt; [COLOR=#000080]200[/COLOR]; i++[COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]
            myBlackHoleIcon = [COLOR=#000000] **new** [/COLOR] BlackHoleIcon[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
            myBlackHoleIcon.[COLOR=#000080]x[/COLOR] = [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]random[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]* [COLOR=#000080]30[/COLOR] + [COLOR=#000080]20[/COLOR];
            myBlackHoleIcon.[COLOR=#000080]y[/COLOR] = [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]random[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]* [COLOR=#000080]30[/COLOR] + [COLOR=#000080]20[/COLOR];
            
            myBlackHoleIconContainer.[COLOR=#000080]addChild[/COLOR][COLOR=#000000]([/COLOR]myBlackHoleIcon[COLOR=#000000])[/COLOR];
            [COLOR=#000000]}[/COLOR]
        
        blackHoleIconArray.[COLOR=#0000FF]push[/COLOR][COLOR=#000000]([/COLOR]myBlackHoleIconContainer[COLOR=#000000])[/COLOR];
        addChild[COLOR=#000000]([/COLOR]myBlackHoleIconContainer[COLOR=#000000])[/COLOR];
        

        [COLOR=#000000]}[/COLOR]

```

[COLOR=#808080]_//BLACK HOLE ICON VS FALCON_[/COLOR]  
[COLOR=#0000FF]for[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#000000] **var** [/COLOR] blackHoleNum:[COLOR=#0000FF]int[/COLOR]=blackHoleIconArray.[COLOR=#0000FF]length[/COLOR] - [COLOR=#000080]1[/COLOR]; blackHoleNum \>= [COLOR=#000080]0[/COLOR]; blackHoleNum–[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]

```
                [COLOR=#808080]*/*playSound(shipHit);*/*[/COLOR]
                removeChild[COLOR=#000000]([/COLOR]myBlackHoleIconContainer[COLOR=#000000])[/COLOR];
                addDisplayBlackHoleIcon[COLOR=#000000]([/COLOR]displayBlackHoleIconCount,[COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR];
                isBlackHolePowerActive = [COLOR=#000000] **true** [/COLOR];
                

            [COLOR=#000000]}[/COLOR]
        [COLOR=#000000]}[/COLOR]

```

[/LEFT]

---

<div class="post-metadata">

**Author:** ![inquizard](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@inquizard](https://forum.kirupa.com/u/inquizard)\
**Post date:** [May 26, 2008, 12:28pm UTC](https://forum.kirupa.com/t/removechild/261319/2 "2008-05-26T12:28:38Z")

</div>

am i reading this right - you want to remove the object, not the container? if so is your removeChild right? it’s referencing the container and not the object?

---

<div class="post-metadata">

**Author:** ![RebuiltJorge](https://avatars.discourse-cdn.com/v4/letter/r/94ad74/32.png) [@RebuiltJorge](https://forum.kirupa.com/u/RebuiltJorge)\
**Post date:** [May 26, 2008, 12:34pm UTC](https://forum.kirupa.com/t/removechild/261319/3 "2008-05-26T12:34:38Z")

</div>

I want to remove the container which will in return remove what ever is inside it

---

<div class="post-metadata">

**Author:** ![RebuiltJorge](https://avatars.discourse-cdn.com/v4/letter/r/94ad74/32.png) [@RebuiltJorge](https://forum.kirupa.com/u/RebuiltJorge)\
**Post date:** [May 27, 2008, 1:48pm UTC](https://forum.kirupa.com/t/removechild/261319/4 "2008-05-27T13:48:49Z")

</div>

amazing, thanks!
