If you've ever wanted to execute some code when a Spark Label's text is truncated, you may hope that binding to the isTruncated property would do the job. For example, you may want to set the background colour:


<s:Label id="labelA
 backgroundColor="{labelA.isTruncated ? 0xFF0000 : 0xFFFFFF}" />

However, the isTruncated property isn't bindable, so you need to dig a little deeper. Inside the TextBase class, the setIsTruncated() method dispatches a isTruncatedChanged event when the truncation state changes. This event isn't in the meta data, so you need to assign an event handler manually:

<s:Label id="labelB"
 creationComplete="labelB_creationCompleteHandler(event)"/>

The creation complete handler assigns a further handler when the isTruncatedChanged event is fired to set the background colour:

<fx:Script>
<![CDATA[
 import mx.events.FlexEvent;

 protected function labelB_creationCompleteHandler(event:FlexEvent):void
 {
  labelB.addEventListener('isTruncatedChanged', isTruncatedChangeHandler)
 }

 private function isTruncatedChangeHandler(event : Event):void
 {
  labelB.setStyle('backgroundColor', labelB.isTruncated ? 0xFF0000 : 0xFFFFFF); 
 }
]]>
</fx:Script>


0

Add a comment

About Me
About Me
Labels
Labels
Blog Archive
Loading