remove()
Remove the object from the canvas.
Description
Remove the object from the canvas. Also removes the children of the object from canvas.
Arguments
- redraw : Boolean (since version 2.1.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 and a rectangle that we add to the canvas. Then we add an event handler that removes the rectangle when clicked.
View Example
Code
var canvas = oCanvas.create({
canvas: "#canvas",
background: "#ccc"
});
var rectangle = canvas.display.rectangle({
x: 77,
y: 100,
width: 200,
height: 100,
fill: "#000"
});
canvas.addChild(rectangle);
rectangle.bind("click tap", function () {
this.remove();
});
Output