16
Feb
08

Setting the value of a Flex Progress Bar

This question came up on the Adobe Flex Forums the other day and I was a little surprised to see that I hadn’t already covered the topic.

The following example shows how you can manually set the progress of a ProgressBar in Flex by using the setProgress() method.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/02/16/setting-the-value-of-a-flex-progress-bar/ -->
<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 slider_change(evt:SliderEvent):void {
                progressBar.setProgress(evt.value, progressBar.maximum);
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="setProgress():">
                <mx:HSlider id="slider"
                        minimum="0"
                        maximum="360"
                        value="0"
                        liveDragging="true"
                        snapInterval="1"
                        tickInterval="10"
                        change="slider_change(event);"
                        width="{progressBar.width}" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:ProgressBar id="progressBar"
            mode="manual"
            minimum="0"
            maximum="360" />

</mx:Application>

View source is enabled in the following example.


15 Responses to “Setting the value of a Flex Progress Bar”


  1. 1 me Apr 4th, 2008 at 6:21 am

    does not work

  2. 2 peterd Apr 4th, 2008 at 8:15 am

    me,

    What isn’t working?

  3. 3 William Apr 4th, 2008 at 9:48 am

    I want to make an indeterminate progress bar that just spins. I want to be able to make it visible, then turn it on so that it just spins, then turn it off and make it invisible…all programatically. Is there a reference for this somewhere?

    The context: I am submitting a “commit” to a custom data service. I want to show a spinning icon until the commit is reported as “confirmed”.

    Thanks

  4. 4 peterh Apr 28th, 2008 at 12:10 pm

    Demo doesn’t work for me either - I think that moving the slider will set the progress bar to that %, but in this demo, moving the slider bar has no effect on the progressbar and nothing changes besides the slider’s position and tooltip.

  5. 5 peterd Apr 28th, 2008 at 12:16 pm

    peterh,

    Interesting. The example in the HTML page above works for me on two different machines.
    Which OS and Flash Player version are you using?
    http://blog.flexexamples.com/about-you/

    Peter

  6. 6 sunild May 17th, 2008 at 1:51 am

    Hi Peter,

    Thanks for your awesome site!

    As some people have pointed out, I found this example to be broken, but only on my Mac. Works fine on an XP box. Here are the Flash versions I am using:

    Mac: OS X 10.4, Flash: MAC 9,0,124,0 (debug)

    Windows XP: WIN 9,0,115,0 (debug)

    Sunil

  7. 7 Julien Graglia May 29th, 2008 at 12:05 am

    Didn’t work for me neither. (the slider has no effect on the progress bar)
    In both linux and Xp :

    Xp Pro SP2, IE7, Flash 9,0,124,0 Debug

    Ubuntu 8.04, Firefox 3.0b5, Flash 9,0,124,0 Debug

  8. 8 peterd May 29th, 2008 at 12:31 am

    Fascinating. I’m using WIN 9,0,115,0 (debug) on Win XP SP2/IE7 and the previous example works fine for me.

    Peter

  9. 9 Anonymous Jul 11th, 2008 at 1:15 pm

    Hi,

    Its not working for me also….

    progressBar.maximum is 0 at the time of change event of slider…

    dfodiode

  10. 10 Marcel Ray Jul 19th, 2008 at 9:46 am

    Convinced that I was doing something wrong with setting progress in my app, I stumbled upon this example. Lo and behold, it doesn’t work for me either!

    I’m on Mac OS 10.5.4, player version 9.0.124 debug.

    Anyone able to shed any light on this?

  11. 11 GregL Aug 4th, 2008 at 9:54 am

    This example does not work for me either.

    Incidentally, I’m using 9,0,124,0 (debug)…and it looks like everyone else who can’t get it to work is using the 9,0,124,0 version of the player.

  12. 12 Nick Aug 23rd, 2008 at 11:05 am

    This looks to be like a bug in flex. I see same problem. “progressBar.maximum” is getting defaulting to 0. Change it to 360, and it will run fine.

  13. 13 ian Sep 8th, 2008 at 10:39 am

    10,0,2,26 mac debug is also not working

  14. 14 peterd Sep 8th, 2008 at 12:41 pm

    Thanks everybody,

    The workaround seems to be using slider.maximum or hardcoding 360 instead of relying on progressBar.maximum.

    I’ve filed a bug for this at http://bugs.adobe.com/jira/browse/SDK-16752 and we will investigate it further to see if this is a Flex SDK issue or possibly a Flash Player issue.

    Feel free to add any bug-related comments to the bug in the Flex bug base, SDK-16752.

    Peter

  15. 15 aryan Sep 27th, 2008 at 4:37 pm
    this.mode = "manual";
    

    u have to set the mode to manual orelse it wouldn’t work

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;".