removeChildAt()

Remove the child at the specified index in the children array.

Syntax removeChildAt(index [, redraw])

Return Type displayObject

Description

Remove the child at the specified index in the children array. This will remove the child from the canvas as well.

Arguments

index : Number
The index of the child that will be removed.
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.removeChildAt(0);
});
Output