# Adding a Shape inside a Sprite

**URL:** <https://forum.kirupa.com/t/adding-a-shape-inside-a-sprite/298727>\
**Category:** flash\
**Created:** [October 23, 2009, 5:56pm UTC](https://forum.kirupa.com/t/adding-a-shape-inside-a-sprite/298727 "2009-10-23T17:56:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raabi](https://avatars.discourse-cdn.com/v4/letter/r/41988e/32.png) [@Raabi](https://forum.kirupa.com/u/Raabi)\
**Post date:** [October 23, 2009, 5:56pm UTC](https://forum.kirupa.com/t/adding-a-shape-inside-a-sprite/298727/1 "2009-10-23T17:56:29Z")

</div>

Hello!

I am trying to place a rectangle Shape inside a square Sprite, as its child. But, the child rectangle show up outside the sprite, instead.

Also, the click handler event of the sprite reports the error “_The supplied DisplayObject must be a child of the caller_”.

```auto
 
 
package
{
 import flash.display.Sprite; 
 import flash.display.Shape;
 import flash.text.TextField;
 import flash.events.MouseEvent;
 
 public class Shapes extends Sprite
 {
  var square: Sprite = new Sprite();
  var rect: Shape = new Shape();
 
  public function Shapes()
  { 
   square.graphics.lineStyle(4, 0xFF66CC);
   square.graphics.beginFill(0x990066);
   square.graphics.drawRect(250, 35, 175, 175);
   square.graphics.endFill();
   addChild(square);
 
   rect.graphics.lineStyle(2, 0xFF6600); 
   rect.graphics.beginFill(0xFFCC00, 1); 
   rect.graphics.drawRect(25, 75, 150, 100); 
   rect.graphics.endFill(); 
   square.addChild(rect);
   square.addEventListener(MouseEvent.CLICK, clickHandler);
  }
 
  function clickHandler(ev: MouseEvent): void
  {
   removeChild(rect); // **[COLOR=red]it reports error.[/COLOR]**
  }
 }
} 

```

Any suggestion, please!
