1

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.

Charles
  • 50,943
  • 13
  • 104
  • 142
ina
  • 19,167
  • 39
  • 122
  • 201

2 Answers2

1

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>
Santhosh Nayak
  • 2,312
  • 3
  • 35
  • 65
  • you might already know this, but conventionally, AS3 class names are CamelCase and instance names are headlessCamelCase. – Pranav Hosangadi Dec 10 '11 at 10:27
  • Apparently calling the resize listener was what was needed to update the height value properly! Thanks!! :) – ina Dec 11 '11 at 05:34
0

If I understood your question correctly, you can listen to mx.events.FlexEvent.UPDATE_COMPLETE

Charles
  • 50,943
  • 13
  • 104
  • 142
  • The trace is done after a data load complete listener `datasource.addEventListener(ResultEvent.RESULT,getheights);` - also `datasource.addEventListener(FlexEvent.UPDATE_COMPLETE,getheights);` loads an error access of undefined property FlexEvent – ina Dec 10 '11 at 03:22
  • @ina `import mx.events.FlexEvent;` are you using this? – Santhosh Nayak Dec 10 '11 at 06:38
  • Added the import, but, the UPDATE_COMPLETE is not triggered even when data loads... – ina Dec 10 '11 at 09:06