removeChild()

Remove the passed in child from the object.

Syntax removeChild(object [, redraw])

Return Type displayObject

Description

Remove the passed in child from the object. This will remove the child from the canvas as well.

Arguments

object : displayObject
An object that inherits from the base displayObject. This could be either a predefined display object, or a user-defined created with the register() method.
redraw : Boolean (since version 2.6.0)
If set to false, the canvas will not be redrawn right after the object is removed from the canvas. Can be used if you are removing lots of objects at the same time, but only want to redraw once when it's done.

Return Value

displayObject. Returns the display object itself.

Examples

Example 1

We create a new core instance, a rectangle and a square. Then we add the rectangle to the canvas and add the square as a child to the rectangle. Finally we add an event handler that removes square when the rectangle is clicked.

View Example
Code
var canvas = oCanvas.create({
	canvas: "#canvas",
	background: "#ccc"
});

var rectangle = canvas.display.rectangle({
	x: 77,
	y: 270,
	width: 200,
	height: 100,
	fill: "#000"
});

var square = canvas.display.rectangle({
	x: 10,
	y: 10,
	width: 50,
	height: 50,
	fill: "#0ff"
});

canvas.addChild(rectangle);

rectangle.addChild(square);

rectangle.bind("click tap", function () {
	this.removeChild(square);
});
Output