tags:

views:

918

answers:

5

How can I use strikethrough in a Label or text in flex 3 ?

A: 

You can use a TextGraphic from the Flex Gumbo SDK (Using the beta Gumbo SDK in Flex Builder 3).

Source

Samuel
A: 

But is there any way of doing this in flex 3 using SDK 3 ?

Code Burn
A: 

Depending on your exact needs, you might be able to subclass label, override the updateDisplayList, and just draw a line through the middle of the text.

rogueg
A: 

Flex 3 example here: http://flexsnippets.mediagreenhouse.com/?p=46

+2  A: 

I needed the same, and ended up simplifying the mediagreenhouse solution somewhat:

package

{ import flash.text.TextLineMetrics; import mx.core.mx_internal; import mx.controls.Label;

use namespace mx_internal;

public class StrikeLabel extends Label
{

 public function StrikeLabel()
 {
  super();
 }

 override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
 {
  super.updateDisplayList( unscaledWidth, unscaledHeight );

  if( textField )
  {
   var metrics : TextLineMetrics = textField.getLineMetrics( 0 );
   var y : int = ( metrics.ascent * 0.66 ) + 2;

   graphics.clear();
   graphics.lineStyle( 1, getStyle( "color" ), 1 );
   graphics.moveTo( 0, y );
   graphics.lineTo( metrics.width, y );
  }
 }
}

}

Ward
This works great until the text is multi-line, then it only strikesthrough the top line.
invertedSpear
I fixed it with this copy everything below and format it and you'll see what I'm doing: `copy below this`var nLines:uint = super.mx_internal::getTextField().numLines; var yPos:int = 0; for(var i:int = 0; i<nLines;i++){var metrics:TextLineMetrics = super.getLineMetrics(i);var y:int = Number(metrics.ascent * .66)+2;yPos += y; graphics.lineStyle( 1, getStyle( "color" ), 1 ); graphics.moveTo( 0, yPos );graphics.lineTo( metrics.width, yPos ); yPos -= y; yPos+=metrics.height;} copy that and format it and you'll see what I'm doing.
invertedSpear