# Keywords: parent, child and root. How do they work?

**URL:** <https://forum.kirupa.com/t/keywords-parent-child-and-root-how-do-they-work/257085>\
**Category:** flash\
**Created:** [April 10, 2008, 2:45am UTC](https://forum.kirupa.com/t/keywords-parent-child-and-root-how-do-they-work/257085 "2008-04-10T02:45:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![entropy\_7](https://avatars.discourse-cdn.com/v4/letter/e/6bbea6/32.png) [@entropy\_7](https://forum.kirupa.com/u/entropy_7)\
**Post date:** [April 10, 2008, 2:45am UTC](https://forum.kirupa.com/t/keywords-parent-child-and-root-how-do-they-work/257085/1 "2008-04-10T02:45:51Z")

</div>

I’m having the following situation when using AS3:

I’m adding a movieClip from the library in Flash CS3 to the stage by using addChild. I call addChild from a function within the constructor of a class.

I do it as follows: parent.addChild(myMovieClip);

Later when i intend to remove the movieClip, then removeChild is called from within another function in the constructor.  
So then i do parent.removeChild(), which works.  
But in another instance i call removeChild in a function within a function in the constructor, after which i do parent.parent.removeChild(). However the last instance gives an error during runtime in the output window.

I suspect i do not fully understand the concept of the keywords, parent, child and root. I can’t seem to get things to work without errors emerging in the output window during runTime.

The following errors emerge in the output window:  
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.  
at flash.display: ![](http://forum.kirupa.com/uploads/kirupa/1495/f1fea26928e562b8.gif)isplayObjectContainer/removeChild()  
at MethodInfo-247()  
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()  
at flash.events::EventDispatcher/dispatchEvent()  
at flash.utils::Timer/flash.utils:Timer::tick()

The way i understood the parent keyword was as follows. When i call addChild in a function in the constructor, then it is called within the scope of that function only, but not in the scope of the constructor. So by doing parent.addChild(); i expand the scope of addChild() to the constructor. So when calling removeChild() from another function i have to access the same scope as i did with addChild. So what i then do is parent.removeChild(); Which seems to work.  
However the trouble comes when i have to call removeChild in a function within a function within the constructor. So that is 1 level deeper than before, but to still be able to access the original scope of the constructor to which addChild() was expanded i do parent.parent.removeChild(). Now exactly this is what i suspect creates the error during runtime, although i’m not entirely sure.  
I suspect that this/my understanding of the parent keyword is wrong as i can’t get it to work properly.  
Can someone explain this concept to me and/or provide a solution to this problem?
