Search code examples
apache-flexactionscriptflex4flexbuilder

Flex 4.6 - Visible Height of Spark Label


I am trying to determine the height of a Spark label that becomes multiline at runtime (due to width property being set), to account for text overflow.

(For a spark label named Title) I have tried:

Title.measureText(Title.text).height - this seems to return only the height of one line. (Due to differing screen-sizes and font rendering, I don't know in advance how many lines the text would overflow to...)

Title.height - this seems to return the height of the label size (before being re-adjusted at runtime for multiline text flow)

Both properties above return an unchanging value even when different text lengths/multiple lines long are filled in .text

Is there really no way to determine the exact height of an overflow Spark label?


I am admittedly not that familiar with the Flex API but after scouring the manual for quite some time, I am still unable to place this title label with the proper spacing. Any help would be appreciated.


Solution

  • I think resize event of Spark label will be usefull.
    just try this example application This may Help You

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:mx="library://ns.adobe.com/flex/mx" >
    
    <fx:Script>
        <![CDATA[
            public var Height:String="";
            public function Resize():void
            {
                Height=lblLabel.height.toString();
                txtText.text="Label Height:  "+Height;
            }
            public function AddText():void
            {
                lblLabel.text += lblLabel.text;
            }
    
    
        ]]>
    </fx:Script>
        <mx:Text id="txtText"  x="46" y="44" width="200"/>
        <s:Label  id="lblLabel" text="Label Text " x="46" y="99" width="200"  resize="Resize()"/>
        <s:Button id="btnClick" label="AddText" click="AddText()" x="199" y="43"/>
    </s:Application>