Setting the track color of a Flex ProgressBar control

by Peter deHaan on February 8, 2008

in ProgressBar

The following example shows you how you can set the track colors on a ProgressBar control in Flex by setting the trackColors style to an array of two values.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/02/08/setting-the-track-color-of-a-flex-progressbar-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            private function progressBar_initialize():void {
                progressBar.setProgress(76, 100);
            }
        ]]>
    </mx:Script>

    <mx:ProgressBar id="progressBar"
            mode="manual"
            labelPlacement="center"
            fontSize="48"
            barColor="haloBlue"
            trackColors="[white, haloSilver]"
            trackHeight="64"
            width="100%"
            initialize="progressBar_initialize();" />

</mx:Application>

View source is enabled in the following example.

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

<mx:Style>
    ProgressBar {
        barColor: haloBlue;
        trackColors: white, haloSilver;
        trackHeight: 64;
    }
</mx:Style>

Or, you can set the trackColors style using ActionScript, as seen in the following snippet:

<mx:Script>
    <![CDATA[
        private function progressBar_initialize():void {
            progressBar.setProgress(76, 100);
            // Set styles...
            progressBar.setStyle("barColor", "haloBlue");
            progressBar.setStyle("trackColors", ["white", "haloSilver"]);
            progressBar.setStyle("trackHeight", 64);
        }
    ]]>
</mx:Script>

If you want the ProgressBar control’s track to have a solid fill, set both colors the trackColors style to the same value, as seen in the following snippet:

<mx:Style>
    ProgressBar {
        barColor: haloBlue;
        trackColors: black, black;
        trackHeight: 64;
    }
</mx:Style>

{ 3 comments… read them below or add one }

1 jonas February 8, 2008 at 7:00 pm

it seems that embedded font can not affect progressBar’s fontFamily anywhere, am I missed anything?

Reply

2 peterd February 9, 2008 at 11:45 pm

jonas,

By default the progress bar’s font weight is “bold”. You need to make sure you are embedding a bold font weight, or you set the progress bar’s fontWeight style to “normal”.

For more information, see “Using an embedded font with the Flex ProgressBar control”.

Peter

Reply

3 jonas February 10, 2008 at 5:26 am

Your help was greatly appreciated! say thanks again

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: