# addChild same Instance gets duplicated, why?

**URL:** <https://forum.kirupa.com/t/addchild-same-instance-gets-duplicated-why/272954>\
**Category:** flash\
**Created:** [October 9, 2008, 5:01pm UTC](https://forum.kirupa.com/t/addchild-same-instance-gets-duplicated-why/272954 "2008-10-09T17:01:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![oskaraqp](https://avatars.discourse-cdn.com/v4/letter/o/8e8cbc/32.png) [@oskaraqp](https://forum.kirupa.com/u/oskaraqp)\
**Post date:** [October 9, 2008, 5:01pm UTC](https://forum.kirupa.com/t/addchild-same-instance-gets-duplicated-why/272954/1 "2008-10-09T17:01:33Z")

</div>

Hi, I was wondering if you could help me with this doubt I have with addChild(), since all the info I’ve found don’t help me much, for example I have this code :

private var \_roundRect:miClass;  
private var \_width:Number;  
private var \_height:Number;  
publich function createRect():void{  
\_roundRect = new miClass(\_width,\_height);  
\_roundRect.start();//this just draws a block, and place a text,  
addChild(\_roundRect);  
}  
public function updateRect($w:Number,$h:Number):void{  
\_width=$w;  
\_height=$h;  
createRect();  
}

when I test this, first I create the rect, then it is added to the screen using addChild, then if I call update the addChild adds a new instance of rect, which is weird since I’m not creating a new object, I’m just changing the properties of a private var, but I get a new visible object on the screen, as I’ve read on flash doc addChild just move a object on the screen if it is already there, for example using flash and I place and object in the stage, then I create other object a sprite and I use spritename.addCHild(objectOnTheStage) the object gets moved no duplicated, on flash documentation it also says that addchild is used to move an object over all the objects of a container, it is not get duplicated, it is moved, this is driving me a little crazy, could you please give me an explain or show me a link which explains this better, I’ve checked a lot on the web but no luck.

Thank u so much. Oscar.
