Setting a complete effect on a ProgressBar control in Flex

by Peter deHaan on March 15, 2008

in ProgressBar

The following example shows how you can apply an effect that plays once a Flex ProgressBar control completes (reaches 100%).

Full code after the jump.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/15/setting-a-complete-effect-on-a-progressbar-control-in-flex/ -->
<mx:Application name="ProgressBar_completeEffect_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">
 
    <mx:Script>
        <![CDATA[
            private var timer:Timer;
 
            private function init():void {
                timer = new Timer(10);
                timer.addEventListener(TimerEvent.TIMER, timer_timer);
            }
 
            private function timer_timer(evt:TimerEvent):void {
                progressBar.setProgress(progressBar.value + 1, 100);
            }
 
            private function progressBar_complete(evt:Event):void {
                timer.stop();
            }
 
            private function resetProgressBar():void {
                progressBar.setProgress(0, 100);
                progressBar.scaleX = 1.0; // 100%
                progressBar.scaleY = 1.0; // 100%
                progressBar.alpha = 1.0; // 100%
            }
 
            private function playProgressBar():void {
                resetProgressBar();
                timer.start();
            }
        ]]>
    </mx:Script>
 
    <mx:Parallel id="progressBar_completeEffect">
        <mx:Fade alphaTo="0.0" />
        <mx:Zoom zoomHeightTo="0" />
    </mx:Parallel>
 
    <mx:ApplicationControlBar dock="true">
        <mx:Button label="Play"
                click="playProgressBar();" />
        <mx:Button label="Reset"
                click="resetProgressBar();" />
    </mx:ApplicationControlBar>
 
    <mx:ProgressBar id="progressBar"
            complete="progressBar_complete(event);"
            completeEffect="{progressBar_completeEffect}"
            mode="manual"
            labelPlacement="center"
            width="80%"
            height="60%"
            creationComplete="init();" />
 
</mx:Application>

View source is enabled in the following example.

{ 6 comments… read them below or add one }

1 Michael March 16, 2008 at 3:02 am

No compiled SWFs anymore?
BTW, great blog!!

Thanks,
Michael

Reply

2 peterd March 16, 2008 at 7:44 am

Michael,

Sorry, I’ve been too busy, I’ll try and upload the files later today.

Peter

Reply

3 peterd March 17, 2008 at 8:45 am

SWF added.

Reply

4 Frederik September 3, 2009 at 6:53 am

Just a short note in case anyone else using Flex 4 stumbles upon this post ( like I did).

If you’re encountering an “is not assignable to target type Array or target element type mx.core.IVisualElement” error just wrap the mx:Parallel with an fx:Declarations element.

 

for more information see http://www.adobe.com/devnet/flex/articles/flex3and4_differences_03.html

Reply

5 YvesC November 13, 2009 at 4:11 pm

This blog is awesome, I’ve learned so much from it. Many thanks for all your great effort.

Reply

6 Kola February 8, 2010 at 9:09 am

Is it possible to attach progressBar to the cursor?

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: