Hello!
Experimenting with adding a square shape inside a rectangle, in the following code, the compiler bounced the error:
"
Call to a possibly undefined method addChild through a reference with static type flash.display:Shape".
Code:
package
{
import flash.display.Sprite;
import flash.display.Shape;
public class Shapes extends Sprite
{
public function Shapes()
{
var rect: Shape = new Shape();
rect.graphics.lineStyle(2, 0xFF6600);
rect.graphics.beginFill(0xFFCC00, 1);
rect.graphics.drawRect(25, 75, 175, 75);
rect.graphics.endFill();
addChild(rect);
var square: Shape = new Shape();
square.graphics.lineStyle(4, 0xFF66CC);
square.graphics.beginFill(0x990066);
square.graphics.drawRect(250, 35, 75, 75);
square.graphics.endFill();
//the following statement cause the error.
rect.addChild(square);
}
}
}
It simply smashed my faith that addChild() method applies to every type of shape. Would anybody kindly rectify my mistake, please!