Air ToolBox: AutoResizeHTML

Jan 08, 2009

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...

  1. 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.
  2. load the new HTMLText from 'it's self'.
  3. Perform a secondary measurment of the HTMLText to check to see if 30% of the screen is too big.
    1. 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.
    2. 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)

Comments

Russell Brown

Russell Brown wrote on 02/18/09 11:28 AM

This is a test

Write your comment



(it will not be displayed)



Subscribe to this comment thread