Setting the background color and background alpha for a NumericStepper control in Flex

by Peter deHaan on May 23, 2008

in NumericStepper

The following example shows how you can set the background color and background alpha for a Flex NumericStepper control by setting the backgroundColor and backgroundAlpha styles.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/05/23/setting-the-background-color-and-background-alpha-for-a-numericstepper-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="backgroundAlpha:">
                <mx:HSlider id="slider"
                        minimum="0.0"
                        maximum="1.0"
                        value="1.0"
                        snapInterval="0.1"
                        tickInterval="0.1"
                        liveDragging="true" />
            </mx:FormItem>
            <mx:FormItem label="backgroundColor:">
                <mx:ColorPicker id="colorPicker"
                        selectedColor="white" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:NumericStepper id="numericStepper"
            backgroundAlpha="{slider.value}"
            backgroundColor="{colorPicker.selectedColor}" />

</mx:Application>

View source is enabled in the following example.

You can also set the backgroundAlpha and backgroundColor styles in an external .CSS file or <mx:Style /> block, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/05/23/setting-the-background-color-and-background-alpha-for-a-numericstepper-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Style>
        NumericStepper {
            backgroundAlpha: 0.5;
            backgroundColor: red;
        }
    </mx:Style>

    <mx:NumericStepper id="numericStepper" />

</mx:Application>

Or you can set the backgroundAlpha and backgroundColor styles using ActionScript, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/05/23/setting-the-background-color-and-background-alpha-for-a-numericstepper-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            private function init():void {
                numericStepper.setStyle("backgroundAlpha", 0.5);
                numericStepper.setStyle("backgroundColor", "red");
            }
        ]]>
    </mx:Script>

    <mx:NumericStepper id="numericStepper"
            creationComplete="init();" />

</mx:Application>

{ 2 comments… read them below or add one }

1 junaid July 27, 2009 at 10:00 pm

if u have the list of all back ground colors (codes)
please send me at my e-mail id
thanx!

Reply

2 Peter deHaan July 28, 2009 at 7:00 am

junaid,

According to the /frameworks/projects/framework/src/mx/styles/StyleManagerImpl.as file, Flex supports the following named colors:
- aqua: #00FFFF
- black: #000000
- blue: #0000FF
- cyan: #00FFFF
- fuchsia: #FF00FF
- gray: #808080
- green: #008000
- lime: #00FF00
- magenta: #FF00FF
- maroon: #800000
- navy: #000080
- olive: #808000
- purple: #800080
- red: #FF0000
- silver: #C0C0C0
- teal: #008080
- white: #FFFFFF
- yellow: #FFFF00

- transparent: “transparent”
- haloBlue: #009DFF
- haloGreen: #80FF4D
- haloOrange: #FFB600
- haloSilver: #AECAD9

Or, you can use any #RRGGBB style color you want.

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: