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