获取flash显示区域 的 getBounds 和 getRect

getBounds(targetCoordinateSpace:DisplayObject):Rectangle
返回一个矩形,该矩形定义相对于 targetCoordinateSpace 对象坐标系的显示对象区域。

getRect(targetCoordinateSpace:DisplayObject):Rectangle
返回一个矩形,该矩形根据 targetCoordinateSpace 参数定义的坐标系定义显示对象的边界,但不包括形状上的任何笔触。

 

 

package 
{
	import flash.display.*;
	import flash.events.Event;
	
	/**
	 * getBounds 获取显示区域矩阵
	 */
	public class Main extends Sprite 
	{
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			// container 
			var container:Sprite = new Sprite();
			container.x = 100;
			container.y = 100;
			this.addChild(container);
			
			// contents
			var contents:Shape = new Shape();
			contents.graphics.lineStyle(1, 0x303030);
			contents.graphics.drawCircle(0, 0, 99.5);
			container.addChild(contents);
			
			trace(contents.width, contents.height);
			// 200 200
			
			trace(container.width, container.height);
			// 200 200
			
			trace(container.x, container.y)
			// 100 100
			
			trace(contents.x, contents.y);
			// 0 0
			
			trace(contents.getBounds(container));
			  // (x=-100, y=-100, w=200, h=200)
			trace(contents.getBounds(this));
			  // (x=0, y=0, w=200, h=200)
			trace(contents.getBounds(contents));
			  // (x=-100, y=-100, w=200, h=200)
			
		}
		
	}
	
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值