getBounds () 方法
public function getBounds(targetCoordinateSpace:DisplayObject):Rectangle
语言版本: ActionScript 3.0
运行时版本: AIR 1.0 Flash Player 9, Flash Lite 4
返回一个矩形,该矩形定义相对于 targetCoordinateSpace 对象坐标系的显示对象区域。考虑以下代码,此代码显示了矩形
的返回方式根据您传递给该方法的 targetCoordinateSpace 参数的不同而不同:
var container:Sprite = new Sprite();
container.x = 100;
container.y = 100;
this.addChild(container);
var contents:Shape = new Shape();
contents.graphics.drawCircle(0,0,100);
container.addChild(contents);
trace(contents.getBounds(container));
// (x=-100, y=-100, w=200, h=200) 得到一个新的矩形,这个新矩形的x,y值,也就是位置是相对于getBounds参数container对象原位置向左向上偏移100。也就是说x,y位置是相对于container的注册点的偏移。
trace(contents.getBounds(this));
// (x=0, y=0, w=200, h=200),这里的this应该是指舞台。位置相对于舞台注册点的偏移。
请注意ÿ
public function getBounds(targetCoordinateSpace:DisplayObject):Rectangle
语言版本: ActionScript 3.0
运行时版本: AIR 1.0 Flash Player 9, Flash Lite 4
返回一个矩形,该矩形定义相对于 targetCoordinateSpace 对象坐标系的显示对象区域。考虑以下代码,此代码显示了矩形
的返回方式根据您传递给该方法的 targetCoordinateSpace 参数的不同而不同:
var container:Sprite = new Sprite();
container.x = 100;
container.y = 100;
this.addChild(container);
var contents:Shape = new Shape();
contents.graphics.drawCircle(0,0,100);
container.addChild(contents);
trace(contents.getBounds(container));
// (x=-100, y=-100, w=200, h=200) 得到一个新的矩形,这个新矩形的x,y值,也就是位置是相对于getBounds参数container对象原位置向左向上偏移100。也就是说x,y位置是相对于container的注册点的偏移。
trace(contents.getBounds(this));
// (x=0, y=0, w=200, h=200),这里的this应该是指舞台。位置相对于舞台注册点的偏移。
请注意ÿ