addChildAt() (since version 2.9.0)

Add the passed in object to the canvas at the specified index in the children list.

Syntax addChildAt(object, index [, redraw])

Return Type Core

Description

Add the passed in object to the canvas at the specified index in the children list. This will immediately trigger a redraw of everything unless specified otherwise.

Arguments

object : displayObject (since version 2.9.0)
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.
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

Core. Returns the core instance itself.

Examples

Example 1

We create three rectangles and add them to the canvas, but the third rectangle (the green one) is added between the other two.

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

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

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

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

canvas.addChild(rectangle1);
canvas.addChild(rectangle2);
canvas.addChildAt(rectangle3, 1);
Output