【AS3代码】深度的设置

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值