Air ToolBox: AutoResizeHTML
Goal: Have a pop-up with a max width of a certain percentage of the screen, but shrink and grow the height of the pop-up based on the size of the content.
I had expected this to be a more built-in feature, but when it wasn't [per my findings] I wrote this AutoResizeHTML extension of MX:HTML. I tried several other approaches and measuring methods that worked, but none that were as consistant and bullet proof as this; but if you know of a better solution than mine, don't be afraid to critic me...
- On the Event.HTML_RENDER event I create a new HTMLloader with a pre-set width to the new maxAutoWidth which in my case is 30% of the current screen width.
- load the new HTMLText from 'it's self'.
- Perform a secondary measurment of the HTMLText to check to see if 30% of the screen is too big.
- If it is too big, I use that number instead. There is no need to check the height, because that number should always be correct.
- If the number is not too big, I resize it's self with the measurements given by the HTMLLoader.
Here is an example of my caller:<xMx:AutoResizeHTML
id="display"
htmlText=""
color="#000000"
horizontalScrollPolicy="off"
verticalScrollPolicy="off"
maxAutoWidth="{maxAutoWidth}"
x="5"
y="5"
/>
Download the latest version of AutoResizeHTML (source code & example)
Russell Brown wrote on 02/18/09 11:28 AM