/*用法:
目标显示对象.getBounds(参照显示对象)//返回一个矩形显示对象区域A(x,y,width,height),
这个A就是目标显示对象的显示区域;
宽度,高度就没啥好说的了,就是这个A的宽和高;
坐标x,y为参照显示对象在A的左上角的坐标值(属于本地坐标);
如果要获得全局坐标参照显示对象应为root。*/
var container:Sprite = new Sprite();
container.x = 150;
container.y = 150;
container.graphics.beginFill(0xfff000);
container.graphics.drawCircle(0,0,50);
this.addChild(container);
var contents:Shape = new Shape();
contents.graphics.beginFill(0xff0000);
contents.graphics.drawCircle(50,50,50);
container.addChild(contents);
//取得root的矩形显示区域;
trace(getBounds(root));
trace(this);
//(x=100, y=100, w=150, h=150)
trace(getBounds(container));
//(x=-50, y=-50, w=150, h=150)
trace(getBounds(contents));
//(x=-50, y=-50, w=150, h=150)
//取得container的矩形显示区域
trace(container.getBounds(root));
//(x=100, y=100, w=150, h=150)
trace(container.getBounds(container));
//(x=-50, y=-50, w=150, h=150)
trace(container.getBounds(contents));
//(x=-50, y=-50, w=150, h=150)
//取得contents的矩形显示区域
trace(contents.getBounds(root));
//(x=150, y=150, w=100, h=100)
trace(contents.getBounds(container));
//(x=0, y=0, w=100, h=100)
trace(contents.getBounds(contents));
//(x=0, y=0, w=100, h=100)
var container:Sprite = new Sprite();
container.graphics.beginFill(0xff0000,1);
container.graphics.drawRect(0,0,200,200);
container.graphics.endFill();
container.x = 100;
container.y = 100;
this.addChild(container);
var contents:Shape = new Shape();
contents.graphics.beginFill(0xffff00,1);
contents.graphics.drawCircle(0,0,100);
contents.graphics.endFill();
container.addChild(contents);
trace(contents.getBounds(container));
// (x=-100, y=-100, w=200, h=200)
trace(contents.getBounds(this));
// (x=0, y=0, w=200, h=200)