How to send images to back in AS3

actionscript-3

Solution

Judging by your confusion as to what you are adding the objects to and the syntax of the code you provided, I am guessing you are already on the top level object. Try this:

this.addChildAt(sun,0);

That will add `sun` to the parent object as the very first item (first = back, last = front). If I'm correct as to which object you are currently in, it should also be the very first item on the stage.

Make sure you read up on things like this before using them: DisplayObjectContainer.addChildAt()

Problem

I want to send the sun and the sunrays to the back of the stage: ``` function CreateRays():Shape { var ray:Shape = new Shape(); ray.graphics.beginFill(0xFF9900,.5); ray.graphics.lineStyle(1,0xFF9900,.5); ray.graphics.lineTo(600,-20); ray.graphics.lineTo(600,20); ray.graphics.lineTo(0,0); ray.graphics.endFill(); return ray; } var sun:Shape = new Shape(); sun.graphics.beginFill(0xFF9900,1); sun.graphics.drawCircle(0,0,30); sun.graphics.endFill(); addChild(sun); setChildIndex(sun, 0); ``` I saw that `setChildIndex(sun, 0);` should do it, but it isn't working.

Original source