Strike Through text component

Recently it was asked on the HOF Flex list how to display text with a strike through. I suggested extending label and using the graphics API, though I had no time at that time to produce the example. While another (Daniel Grace) has provided a mxml based example, here I provide a AS based one that allows for turning the strikethrough on/off at runtime, great for bound data. I’ve attached the component file as well as a simple application example.

StrikeThroughFlexComponent
DK


6 Responses to “Strike Through text component”

  1. May 11th, 2007 | 5:57 am

    Looks like the link to ZIP file is broken.

  2. doug
    May 11th, 2007 | 6:59 am

    Jabby, thanks and sorry about that. Seems I found a wordpress bug.

    DK

  3. May 11th, 2007 | 8:07 am

    Good approach with extending Label component with text “strike-through” functionality, I was thinking of similar approach to use Flash Drawing API to actually draw a line.

    Thumb up!

  4. Lakester
    September 5th, 2007 | 4:46 am

    This component is useful when you need a label with all its text strikethrough.
    But how can I specify only a portion of the text to be strikethrough?

    It would be great if the htmltext methods will support the html tag :(

  5. Sergey
    March 21st, 2008 | 7:25 am

    Great job. I extended your method. I use it for button.
    import mx.controls.Button;
    import mx.events.StyleEvent;

    [Style(name=”textDecoration”, type=”String”, enumeration=”none,underline,strike”, inherit=”no”)]
    public class ExtendedButton extends Button
    {
    public function ExtendedButton()
    {
    super();
    }

    override protected function updateDisplayList(unscaledWidth: Number, unscaledHeight: Number): void
    {
    super.updateDisplayList (unscaledWidth, unscaledHeight);
    this.graphics.clear();
    drawStrike();
    }

    override public function styleChanged(styleProp:String):void
    {
    super.styleChanged(styleProp);
    if (styleProp == “textDecoration”)
    {
    this.invalidateDisplayList();
    }
    }

    private function drawStrike():void
    {
    if (getStyle(”textDecoration”) == “strike”)
    {

    this.graphics.lineStyle(1, this.getStyle(”color”));
    this.graphics.moveTo((width - textField.textWidth) / 2, height/2);
    this.graphics.lineTo((width + textField.textWidth) / 2, height/2);
    }
    else
    {
    this.graphics.clear();
    }
    }
    }

  6. mt
    March 30th, 2008 | 10:18 pm

    How can I create a strikeout itemRenderer component. I want to be able to select a checkbox and thereby applying a strikeout to the entire row.

Leave a reply