Creating drop shadows on the Flex TextInput control

by Peter deHaan on August 30, 2007

in TextInput

The following example shows how you can easily create a drop shadow effect on a TextInput control using the dropShadowEnabled style (instead of creating a DropShadowFilter), as well as control the drop shadow effect’s color, direction, and distance (using the dropShadowColor, shadowDirection, and shadowDistance styles, respectively).

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/30/creating-drop-shadows-on-the-flex-textinput-control/ -->
<mx:Application name="TextInput_dropShadowEnabled_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">
 
    <mx:ApplicationControlBar dock="true">
        <mx:Grid>
            <mx:GridRow>
                <!-- dropShadowEnabled -->
                <mx:GridItem>
                    <mx:CheckBox id="checkBox"
                            label="dropShadowEnabled:"
                            selected="true"
                            labelPlacement="left" />
                </mx:GridItem>
 
                <!-- dropShadowColor -->
                <mx:GridItem>
                    <mx:Label text="dropShadowColor:" />
                    <mx:ColorPicker id="colorPicker" />
                </mx:GridItem>
            </mx:GridRow>
 
            <mx:GridRow>
                <!-- shadowDirection -->
                <mx:GridItem>
                    <mx:Label text="shadowDirection:" />
                    <mx:ComboBox id="comboBox" selectedIndex="1">
                        <mx:dataProvider>
                            <mx:String>left</mx:String>
                            <mx:String>center</mx:String>
                            <mx:String>right</mx:String>
                        </mx:dataProvider>
                    </mx:ComboBox>
                </mx:GridItem>
 
                <!-- shadowDistance -->
                <mx:GridItem>
                    <mx:Label text="shadowDistance:" />
                    <mx:HSlider id="slider"
                            minimum="-10"
                            maximum="10"
                            value="2"
                            liveDragging="true"
                            snapInterval="1"
                            tickInterval="1"
                            dataTipPrecision="0" />
                </mx:GridItem>
            </mx:GridRow>
        </mx:Grid>
    </mx:ApplicationControlBar>
 
    <mx:TextInput id="textInput"
            dropShadowEnabled="{checkBox.selected}"
            dropShadowColor="{colorPicker.selectedColor}"
            shadowDirection="{comboBox.selectedItem}"
            shadowDistance="{slider.value}" />
 
</mx:Application>

View source is enabled in the following example.

{ 2 comments… read them below or add one }

1 Anonymous September 28, 2009 at 12:48 am

is there a way to change text input color dynamically?

Reply

2 Peter deHaan September 28, 2009 at 6:54 am

@Anonymous,

You mean the text color itself? If so, then yes — you can set the color style to change the text color.

Peter

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: