removeChild()

Remove the passed in object from the canvas.

Syntax removeChild(object [, redraw])

Return Type Core

Description

Remove the passed in object from the canvas, which will trigger a redraw of everything. If the object was never added to the canvas, nothing happens and the method returns the core instance as usual. A better way to remove the object though is to call the remove() method of the display object itself.

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

Core. Returns the core instance itself.

Examples

Example 1

First we create an instance of the core object. Then we create a display object and add it to the canvas. Finally we add an event listener that will remove the object from the canvas when the object is clicked.

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

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

canvas.addChild(rectangle);

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