addAt() (since version 2.9.0)

Add the object to the canvas at a specific index in the children list.

Syntax addAt(index [, redraw])

Return Type displayObject

Description

Add the object to the canvas at a specific index in the children list. Also adds the children of the object to canvas. You can also add the object with core.addChildAt(obj, index), which is more clear as to where the object is added.

Arguments

index : Number (since version 2.9.0)
The index for where in the children list to add the object. If the index is less than or equal to 0 it will be added to the beginning of the list. If the index is more than the index of the last item it will be added to the end of the list.
redraw : Boolean (since version 2.9.0)
If set to false, the canvas will not be redrawn right after the object is added to canvas. Can be used if you are adding 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 two rectangles and add them both to the canvas, but the second rectangle is added underneath the first one.

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

var rectangle1 = canvas.display.rectangle({
	x: 107,
	y: 110,
	width: 200,
	height: 100,
	fill: "red"
});

var rectangle2 = canvas.display.rectangle({
	x: 67,
	y: 100,
	width: 200,
	height: 100,
	fill: "blue"
});

rectangle1.add();
rectangle2.addAt(0);
Output