The following example shows you how you can style the HRule (or VRule) control in Flex by setting the strokeWidth, strokeColor, and shadowColor styles.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/10/14/styling-the-flex-hrule-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:ApplicationControlBar dock="true">
        <mx:Form>
            <mx:FormItem label="stokeWidth:">
                <mx:HSlider id="strokeWidthSlider"
                        minimum="0"
                        maximum="20"
                        value="2"
                        liveDragging="true"
                        snapInterval="1"
                        tickInterval="1"
                        dataTipPrecision="0" />
            </mx:FormItem>
            <mx:FormItem label="strokeColor:">
                <mx:ColorPicker id="strokeColorColorPicker"
                        selectedColor="red" />
            </mx:FormItem>
            <mx:FormItem label="shadowColor:">
                <mx:ColorPicker id="shadowColorColorPicker"
                        selectedColor="blue" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:HRule id="hrule"
            strokeWidth="{strokeWidthSlider.value}"
            strokeColor="{strokeColorColorPicker.selectedColor}"
            shadowColor="{shadowColorColorPicker.selectedColor}"
            width="100%" />

</mx:Application>

View source is enabled in the following example.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

2 Responses to Styling the Flex HRule control

  1. Chad says:

    What I really wish it had were the following…

    cornerRadius
    backgroundColor
    backgroundImage
    borderThickness
    borderStyle

    etc. etc.

    I currently just use the Box, because the Rules just don’t do what I want them to do. Of course, this makes the standards based designer in me cringe, but I guess MXMl isn’t quite XHTML, is it?

  2. peterd says:

    Chad,

    I recommend filing an enhancement request in the Flex bug base, http://bugs.adobe.com/flex/ , for any functionality you think is missing and should be added. I can’t guarantee it would be added in the Flex 3 timeframe, but it helps Adobe guage customer interest. Plus, the more people you can get to vote for your bugs/enhancement requests, the better.

    Peter

Leave a Reply

Your email address will not be published.

You may 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