Avg. Rating 3.7

Problem

Here's how to add a shadow to a button's label rather than to the entire button.

Solution

Extend the Button and apply the DropShadowFilter to the directly to the label.

Detailed explanation

If you try to add a DropShadowFilter to a Button like this:

<mx:Button label="Pick Me" ...>
    <mx:filters>
         <f:DropShadowFilter xmlns:f="flash.filters.*" />
    </mx:filters>
</mx:Button>

all you will get is a drop-shadow on the entire button. Here's how to add a shadow to just the label:

First, create a new class and extend Button. Then override the commitProperties function (or createChildren or even updateDisplayList, but I like commitProperties better) to add the filter to the label (textField, a protected member of the Button class):

override protected function commitProperties():void
{
     super.commitProperties();
     textField.filters = [ new DropShadowFilter() ];
}
If you want to be creative, add styles to your component for the label shadow, color, distance, angle, and alpha. Use those values when creating the drop shadow.

The download contains a class with those styles and the ability to change them at runtime.
ShadowedTextButtons.zip
[Zip contains component class and demo Flex application.]
Report abuse

Related recipes