May
17
2010
Get the view size inside of a Container in Flex
Posted by: Keith H in Components, Flex, tags: Container, EdgeMetrics, Flex 3, Rectangle, viewMetricsFor some odd reason you might want to get the width and height of the inside of a Container. You can use the "viewMetrics" property of a container to do it.
/*-------------------------------------------------------------------
Returns a Rectangle object of the inside view area of a Container,
instead of the complete width and height.
---------------------------------------------------------------------*/
private function getViewRectangle(ui:Container):Rectangle
{
var e:EdgeMetrics=ui.viewMetrics;
var r:Rectangle=new Rectangle();
r.width=ui.width - (e.left + e.right);
r.height=ui.height - (e.top + e.bottom);
r.x=e.left;
r.y=e.top;
return r;
}
In the following example I overlay a green box over a Panel to show how it matches the Panel's size.
Comments are welcome.
Entries (RSS)