读书人

获取flash展示区域 的 getBounds 和 g

发布时间: 2012-12-19 14:13:14 作者: rapoo

获取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);// contentsvar 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 200trace(container.width, container.height);// 200 200trace(container.x, container.y)// 100 100trace(contents.x, contents.y);// 0 0trace(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)}}}

读书人网 >Flash

热点推荐