DisplayObjectContainer - Adobe ActionScript® 3 (AS3 ) API Reference
package{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class DisplayObjectTest01 extends Sprite {
public function DisplayObjectTest01 ():void{
var container:Sprite = new Sprite();
addChild(container);
var circle1:Sprite = new Sprite();
circle1.graphics.beginFill(0xFF0000);
circle1.graphics.drawCircle(40, 40, 40);
circle1.addEventListener(MouseEvent.CLICK, clicked);
var circle2:Sprite = new Sprite();
circle2.graphics.beginFill(0x00FF00);
circle2.graphics.drawCircle(100, 40, 40);
circle2.addEventListener(MouseEvent.CLICK, clicked);
var circle3:Sprite = new Sprite();
circle3.graphics.beginFill(0x0000FF);
circle3.graphics.drawCircle(70, 80, 40);
circle3.addEventListener(MouseEvent.CLICK, clicked);
container.addChild(circle1);
container.addChild(circle2);
container.addChild(circle3);
addChild(container);
function clicked(event:MouseEvent):void {
var circle:Sprite = Sprite(event.target);
var topPosition:uint = container.numChildren - 1;
container.setChildIndex(circle, topPosition);
}
}
}
}
Link
package;
import flash.display.Sprite;
import flash.events.MouseEvent;
class Main extends Sprite
{
var container : Sprite = new Sprite();
public function new()
{
super();
//var container : Sprite = new Sprite();
addChild(container);
var circle1 : Sprite = new Sprite();
circle1.graphics.beginFill(0xFF0000);
circle1.graphics.drawCircle(40, 40, 40);
circle1.addEventListener(MouseEvent.CLICK, clicked);
var circle2 : Sprite = new Sprite();
circle2.graphics.beginFill(0x00FF00);
circle2.graphics.drawCircle(100, 40, 40);
circle2.addEventListener(MouseEvent.CLICK, clicked);
var circle3 : Sprite = new Sprite();
circle3.graphics.beginFill(0x0000FF);
circle3.graphics.drawCircle(70, 80, 40);
circle3.addEventListener(MouseEvent.CLICK, clicked);
container.addChild(circle1);
container.addChild(circle2);
container.addChild(circle3);
addChild(container);
}
function clicked(event : MouseEvent) : Void{
var circle : Sprite = cast((event.target), Sprite);
var topPosition : Int = container.numChildren - 1;
container.setChildIndex(circle, topPosition);
};
}
DisplayObjectTest01