Get a display object's rectangle in another object's coordinate space
snipped by vixiom
An alternative to jumping around with globalToLocal and localToGlobal if you need to get one object's location in another's coordinate space. getRect excludes any strokes, if you want the size plus position with strokes use getBounds.
The code below creates two MovieClips puts one in the other and returns the child's Rectangle size and position in relation to the root level.
var container:MovieClip = new MovieClip(); var child:MovieClip = new MovieClip(); addChild( container ); container.addChild( child ); container.x = 50; container.y = 50; child.graphics.beginFill( 0x000000, 1 ); child.graphics.drawRect( 0, 0, 200, 200 ); child.graphics.endFill(); child.x = 50; child.y = 50; var rect:Rectangle = new Rectangle(); rect = child.getRect( root ); // traces out child's rectangle in root space trace( rect );




