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)
}
}
}