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.
Follow Cubicleman
-
Recent Posts
Categories
Speaking at:
Atlanta Adobe User Groups
Suggested Reading
Amazon Wish List


.
I'm Speaking!
I’m Speaking
Looks like the link to ZIP file is broken.
Jabby, thanks and sorry about that. Seems I found a wordpress bug.
DK
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!
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
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();
}
}
}
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.
Great post!!
.
Thank you very much. This is just what I was looking for
I modified this a bit and used it for a CheckBox component:
package components
{
import flash.events.MouseEvent;
import flash.events.Event;
import mx.controls.CheckBox;
public class CheckBoxStrikeable extends CheckBox
{
public function CheckBoxStrikeable()
{
super();
this.addEventListener ( MouseEvent.CLICK, onClicked );
this.addEventListener( Event.ADDED_TO_STAGE, onInit);
}
private function onInit (EV:Event) : void
{
updateStyle();
}
private function onClicked (ME:MouseEvent) : void
{
updateStyle();
}
private function updateStyle () : void
{
if (this.selected)
{
this.graphics.lineStyle(1.5, this.getStyle(“color”), 1);
this.graphics.moveTo((width – textField.textWidth) / 2 + 10, height/2);
this.graphics.lineTo((width + textField.textWidth) / 2 + 10, height/2);
}
else
this.graphics.clear();
}
}
}