How to create a Flex application with dynamic height


Is there a way to allow a flex application to have a dynamic height while embedded in an HTML wrapper?

I want the Flex application to grow in height in a way that it will not cause vertical scroll bars.

Best Solution

The best way should be overriding the Application's measure method like:

private var _lastMeasuredHeight:int;

override protected function measure():void
    if (measuredHeight != _lastMeasuredHeight)
        _lastMeasuredHeight = measuredHeight;
        if (ExternalInterface.available)
  "setFlashHeight", measuredHeight);

This function assumes that you have a javascript function named setFlashHeight which can accept a height (or whatever you name it) parameter. An example would be:

function setFlashHeight(newHeight){
    //assuming flashDiv is the name of the div contains flex app.
    var flashContentHolderDiv = document.getElementById('flashDiv'); = newHeight;

I use swfobject to embed my flex applications. So the flash object resides inside a div. If yours not; the js function could easily be altered to set the flash object's height. When you implement this solution, you'll notice that scrollBars aren't working as flash consumes the event. But that's another subject...

Related Question