2 Replies Latest reply on Jul 19, 2010 12:48 PM by shawnyale

    Is there a way to get a resized element height by ILayoutElement??

    shawnyale Level 1

      Hi all,

      I am currently working on a means of layout out dynamic text and want my layout to check the RichText component to determine if it has enough space horizontally to fit in the available real estate.  For example, if the available browser width is 300px, and the RichText is 200px, everything is fine and the component can be placed without modification.

       

      However, if the browser is 300px and the component is 400px, I want to resize the component to fit into the available space and trigger the RichText to present its content in a multi-line format.  I'm really close to a solution, but Ive been unable to find out if there is any means to get the height that the component will be once the width resize is complete.

       

      The crux of this approach relies upon using ILayoutElement within the layout and resizing as follows:

       

      element.setLayoutBoundsSize(target.width-HorizontalGap, NaN)

       

      Now I know that setting the height to NaN causes this method to set the elements height to its preferred height.  I've checked the other available methods such as element.getLayoutBoundsHeight(), element.getPreferredBoundsHeight(), element.getMaxboundsHeight() but these all appear to return the height as if the resize for multi-line didn't exist.

       

      My question is that I would like to find a way to figure out what the new height is GOING to be once the width resize occurs.

       

      Any thoughts?  Thanks in advance!

       

      PS. While stepping through, I noticed there is a protected $height that appears to have the correct height, but there doesn't seem to be a way to access it.  Do I need to subclass ILayoutElement to make this value available or is there something Im not seeing.

       

      Cheers!

        • 1. Re: Is there a way to get a resized element height by ILayoutElement??
          Shongrunden Adobe Employee

          You can get at the $height property in the mx_internal namespace, for example:

           

          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                         xmlns:s="library://ns.adobe.com/flex/spark"
                         creationComplete="init()">
             
              <fx:Script>
                  <![CDATA[
                      import mx.core.mx_internal;
                      use namespace mx_internal;
                     
                      private function init():void {
                          trace(btn.mx_internal::$height);
                      }
                  ]]>
              </fx:Script>
             
              <s:Button id="btn" />
             
          </s:Application>
          1 person found this helpful
          • 2. Re: Is there a way to get a resized element height by ILayoutElement??
            shawnyale Level 1

            ok so as it turns out, the $height in the component appears to only be the height of a single line.  What I really want is the complete height of the component when I allow Flex to resize.  For example:

             

            I have 200px of available space and the RichText has 300px of text.  I want to know the height of the entire component once Flex has resized it to multi-line so that I can tell how far down my next line needs to be.  To accomplish this, I'm doing the following:

             

            if(element.getLayoutBoundsWidth() > target.width)

            {

                 element.setLayoutBoundsSize(target.width, NaN);  // I'm not setting the height of the component because Flex is doing that based upon the width

            }

             

            The problem is that even after calling setLayoutBoundsSize(), when I call element.getLayoutBoundsHeight() (or element.getLayoutBoundsHeight(true) ), it's still giving me the height of a single line of text and not the total height with multi-line.  I need a way to tell the entire height of the component after Flex has resized for multi-line.

             

            Thanks so much and I appreciate any help I can get.