# Nested Shapes vs. Nested Sprites in AS 3.0

**URL:** <https://forum.kirupa.com/t/nested-shapes-vs-nested-sprites-in-as-3-0/260852>\
**Category:** flash\
**Created:** [May 20, 2008, 2:23pm UTC](https://forum.kirupa.com/t/nested-shapes-vs-nested-sprites-in-as-3-0/260852 "2008-05-20T14:23:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![clem\_c\_rock](https://avatars.discourse-cdn.com/v4/letter/c/c6cbf5/32.png) [@clem\_c\_rock](https://forum.kirupa.com/u/clem_c_rock)\
**Post date:** [May 20, 2008, 2:23pm UTC](https://forum.kirupa.com/t/nested-shapes-vs-nested-sprites-in-as-3-0/260852/1 "2008-05-20T14:23:33Z")

</div>

Nested Shapes vs. Nested Sprites in AS 3.0

Hello,  
I’m trying to learn Actionscript 3.0 from the ground up. I am trying to figure out why I can’t create nested shape objects in the manner that’s demonstrated below w/ Sprite objects.

var container:Shape = new Shape();

When I change the below from a Sprite to a Shape I get this error:

“Call to a possibly undefined method addChild through a reference with static type flash.display:Shape.”

var container:Sprite = new Sprite();  
container.graphics.lineStyle(0,0xFF6600);  
container.graphics.beginFill(0xFF3300);  
container.graphics.moveTo(0, 0); // start line @ 10.\_x and 0 Y  
container.graphics.lineTo(100, 0); // move to left 65 x and 0 y  
container.graphics.lineTo(100, 100); // from 65 x to 20 y  
container.graphics.lineTo(0,100); // 0 x to 20 y

this.addChild(container);  
container.x = 140;  
container.y = 140;

var box\_1:Sprite = new Sprite();  
box\_1.graphics.lineStyle(0,0xFFFFCC);  
box\_1.graphics.beginFill(0xFFFF00);  
box\_1.graphics.moveTo(0, 0); // start line @ 10.\_x and 0 Y  
box\_1.graphics.lineTo(80, 0); // move to left 65 x and 0 y  
box\_1.graphics.lineTo(80, 80); // from 65 x to 20 y  
box\_1.graphics.lineTo(0,80); // 0 x to 20 y

container.addChild(box\_1);  
box\_1.x = 10;  
box\_1.y = 10;

var box\_2:Sprite = new Sprite();  
box\_2.graphics.lineStyle(0,0x92E9FE);  
box\_2.graphics.beginFill(0x92E9FE);  
box\_2.graphics.moveTo(0, 0); // start line @ 10.\_x and 0 Y  
box\_2.graphics.lineTo(60, 0); // move to left 65 x and 0 y  
box\_2.graphics.lineTo(60, 60); // from 65 x to 20 y  
box\_2.graphics.lineTo(0,60); // 0 x to 20 y

box\_1.addChild(box\_2);  
box\_2.x = 10;  
box\_2.y = 10;

Thanks,  
Eric

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [May 20, 2008, 2:29pm UTC](https://forum.kirupa.com/t/nested-shapes-vs-nested-sprites-in-as-3-0/260852/2 "2008-05-20T14:29:12Z")

</div>

Shapes aren’t a subclass of DisplayObjectContainer. They’re meant to be more lightweight, so they can’t have children.
