flash的显示列表的机制探索一

//flash的显示列表子在我看来是个很好的组合模式的例子,今天要写一个程序用到了这个模式,
//突然想到同一个spr在舞台上add两次会不会出现两个呢?于是写代码验证之.
var
spr:Sprite = new Sprite(); spr.graphics.lineStyle(1, 0xff0000); spr.graphics.drawCircle(0, 0, 100); this.addChild(spr); trace(this.numChildren); this.addChild(spr); trace(this.numChildren + " " + this.getChildIndex(spr));//输出:1,0 var spr1:Sprite = new Sprite(); this.addChild(spr1); var spr2:Sprite = new Sprite(); this.addChild(spr2); var spr3:Sprite = new Sprite(); this.addChild(spr3); var spr4:Sprite = new Sprite(); this.addChild(spr4); this.addChild(spr); trace(this.numChildren + " " + this.getChildIndex(spr));//输出:5,4
//结论是,不会,添加两次,显示列表的深度会改变,spr最先被添加深度是0,最后再添加,只是把spr的深度改成了4而已,
原文地址:https://www.cnblogs.com/ilangxm/p/3386355.html