sampleaccessbydepth.as

来自「《Flash AS3殿堂之路》光盘源码 学习ActionScript 3.0」· AS 代码 · 共 45 行

AS
45
字号
package org.kingda.book.display
{
	import flash.display.Sprite;
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Shape;

	public class SampleAccessByDepth extends Sprite
	{
		public function SampleAccessByDepth() {
			
			var a:RectSprite = new RectSprite ("A", 0xB9121B);
			var b:RectSprite = new RectSprite ("B", 0x4c1B1B);
			var c:RectSprite = new RectSprite ("C", 0xF6E497);
			var container:Sprite= new Sprite();
			a.x = 100, a.y = 100;
			b.x = 120, b.y = 120;
			c.x = 140, c.y = 140;
			//生成一个匿名的StarShape对象加入b中
			b.addChild(new StarShape());
			//加入显示列表
			container.addChild(a);
			container.addChild(b);
			container.addChild(c);
			addChild(container);
			
			var star:Shape;
			
			for (var i:int = 0; i<container.numChildren; i++) {
				for (	var j:int = 0; 
						j<(container.getChildAt(i) as Sprite).numChildren; 
						j++	)  
				{		
					var tmpObj:DisplayObject = 
						(container.getChildAt(i) as Sprite).getChildAt(j);
					if (tmpObj is StarShape) {
						star = tmpObj as StarShape;
						trace (i + "|" + j);
					}				
				}
			}
			if (star != null) star.alpha = 0.5;
		}		
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?