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”.
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!