The following example shows how you can set a custom bar skin for a Flex ProgressBar control by setting the barSkin style.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/27/setting-the-bar-skin-on-a-progressbar-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.events.SliderEvent;

            private function init():void {
                var c:Class = progressBar.getStyle("indeterminateSkin");
                progressBar.setStyle("barSkin", c);
                progressBar.setProgress(15, 100);
            }

            private function progressBar_change(evt:SliderEvent):void {
                progressBar.setProgress(evt.value, 100);
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="value:">
                <mx:HSlider id="slider"
                        minimum="0"
                        maximum="100"
                        value="15"
                        liveDragging="true"
                        snapInterval="1"
                        tickInterval="10"
                        dataTipPrecision="0"
                        change="progressBar_change(event);" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:ProgressBar id="progressBar"
            mode="manual"
            labelPlacement="center"
            height="50"
            creationComplete="init();" />

</mx:Application>

View source is enabled in the following example.

You can also set the barSkin style in an external .CSS file or <mx:Style /> block, as seen in the following snippet:

ProgressBar {
    barSkin: ClassReference("mx.skins.halo.ProgressIndeterminateSkin");
}

Or, you can set the barSkin style in MXML using the following snippet:

<mx:ProgressBar id="progressBar"
        barSkin="mx.skins.halo.ProgressIndeterminateSkin"
        mode="manual"
        labelPlacement="center"
        height="50" />
 
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.

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