【AS3代码】深度的设置

论坛 期权论坛 脚本     
匿名技术用户   2021-1-4 03:03   11   0
package
{
import com.ui.Ball;

import flash.display.Sprite;

public class Main extends Sprite
{
var a:Ball = new Ball(0x000000,20);
var b:Ball = new Ball(0x4c1b1b,20);
var c:Ball = new Ball(0xf6e497,20);
var d:Ball = new Ball(0xfcfae1,20);
var e:Ball = new Ball(0xbd8d46,20);

public function Main():void
{
init();
}
private function init():void
{
a.x = 100;
a.y = 100;
b.x = 120;
b.y = 120;
c.x = 140;
c.y = 140;
d.x = 160;
d.y = 160;
e.x = 180;
e.y = 180;

this.addChild(a); //a深度0(最底层)
this.addChild(c); //c深度1
this.addChild(e); //e深度2(最上层)

//设置b的深度为1后,c和e深度自动向后+1
this.addChildAt(b,1);

trace(this.getChildIndex(a)); //a深度0
trace(this.getChildIndex(c)); //c深度2
trace(this.getChildIndex(e)); //e深度3

this.addChild(d);

//直接调换可视对象d和e的深度(调换后深度a0,b1,c2,d3,e4)
this.swapChildren(d,e);

//将倒数第一位的深度和倒数第二位深度上的可是对象对调
this.swapChildrenAt((this.numChildren-2),(this.numChildren-1));

//将c置顶
this.setChildIndex(c,this.numChildren-1);

}

}
}
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP