23
May
08

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

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>

0 Responses to “Setting the background color and background alpha for a NumericStepper control in Flex”


  1. No Comments

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".




Badge Farm

  • Powered by Redoable 1.2
  • Cornify
  • Feeds burnt by Feedburner
  • Feed