views:

75

answers:

1

I'm creating windows in a Flex application (AIR) using the mx:Window component. I'd like the window to be automatically sized to its content (because it will be dynamic), in the same way that an mx:Panel or mx:Box would be.

I've customized components before, so I'm somewhat familiar with the UIComponent lifecycle, but I'm not quite sure how best to do the logic for auto-sizing a container.

If it makes it easier, I'm not expecting that the window auto-size to its content at any time, thought that would be a bonus!

A: 

Try this. Create an interior container, the first (and only) child of the Window (which will contain all the children of the Window and their descendants, and don't set any dimensions on it. Then override the measure method of the Window like so:

override protected function measure() : void {
  super.measure();
  // innerContainer is the interior container mentioned above
  // make sure there is no padding in it, or else figure
  // that into the calculation
  this.width = innerContainer.width;
  this.height = innerContainer.height;
}
Robusto
Doesn't quite get you there as width/height include the OS-specific chrome. Also, would rather not have to build in an extra container. BorderMetrics doesn't seem to give accurate info on the OS chrome.
Troy Gilbert