Progress Bar---

I came up with some code last night to make a progress bar update as 
an image is loaded in my appliction. I have a few photo galleries and 
other things, so I want the user to know that something is loading 
rather than seeing a blank spot on the page... heres my code, you 
might be able to use it.

There is then a progress bar in the application called progress and 
an image called image. Make sure the progress bar's mode is set to 
manual.
        <mx:ProgressBar id="progress" width="200" x="250" y="25" 
mode="manual" source="image" visible="true" barColor="#FF8000"/>
        <mx:Image id="image" x="246" y="19" width="479" height="100%" 
showEffect="{fadeIn}" scaleContent="true" autoLoad="false"/>

script----
                import flash.events.Event;
                import flash.net.URLLoader;
                import flash.display.Loader;
                import flash.net.URLRequest;
                
                public var file:Loader = new Loader();;
                public var fileURL:String = new String();
                public var fileURLReq:URLRequest;
                
                public function imageLoader():void{
                        image.visible=false;
                        progress.setProgress(0,100);
                        progress.visible=true;
                        progress.indeterminate=true;
                        fileURL=galSelTL.selectedItem.full;
                        fileURLReq = new URLRequest(fileURL);
                        file.load(fileURLReq);
                        file.contentLoaderInfo.addEventListener
(Event.OPEN, openHandler);
                        file.contentLoaderInfo.addEventListener
(ProgressEvent.PROGRESS, progressHandler);
                        file.contentLoaderInfo.addEventListener
(Event.COMPLETE, loadCompleteHandler);
                }

                private function openHandler(event:Event):void{
                        progress.indeterminate=false;
                }

                private function progressHandler
(event:ProgressEvent):void{
                        progress.setProgress
(event.bytesLoaded,event.bytesTotal);
                }
        
                private function loadCompleteHandler(event:Event):void
{
                        image.load(fileURL);
                        image.visible=true;
                        progress.visible=false;
                }


good luck,

Jayson


--- In flexcoders@yahoogroups.com, "Giles Roadnight" <[EMAIL PROTECTED]> 
wrote:
>
> I managed to do what I wanted in the by basing it on the examples 
that you
> list and by looking at the examples on livedocs.
> 
>  
> 
> This is what I ended up with:
> 
>  
> 
> The only thing I couldn't get it to do was to make the progress bar 
move as
> data is loaded but the file I am loading is very small so it loads 
in a
> fraction of a second.
> 
>  
> 
> package components
> 
> {
> 
>     import mx.preloaders.*;    
> 
>     import flash.events.ProgressEvent;
> 
>     import flash.events.Event;
> 
>     import flash.display.Sprite;
> 
>     import mx.events.FlexEvent;
> 
>     import mx.events.RSLEvent;
> 
>     import flash.net.URLRequest;
> 
>     import flash.net.URLLoader;
> 
>     import mx.core.Application;
> 
>             
> 
>             public class CustomPreloader extends DownloadProgressBar
> 
>             {
> 
>                         
> 
>                         
> 
>                         public function CustomPreloader()
> 
>                         {    
> 
>                             super();
> 
>                         }
> 
>                         
> 
>         // Override to return true so progress bar appears
> 
>         // during initialization.        
> 
>         override protected function showDisplayForInit(
> 
>                 elapsedTime:int, count:int):Boolean {
> 
>             return true;
> 
>         }
> 
>  
> 
>         // Override to return true so progress bar appears during 
download.
> 
> 
>         override protected function showDisplayForDownloading(
> 
>                 elapsedTime:int, event:ProgressEvent):Boolean {
> 
>             return true;
> 
>         }
> 
>         
> 
>                         private var _preloader:Sprite; 
> 
>                          
> 
>  
> 
>                         override public function set
> preloader(value:Sprite):void
> 
>                         {
> 
>                                     _preloader = value;
> 
>                         
> 
>  
> value.addEventListener(ProgressEvent.PROGRESS, 
progressHandler);      
> 
>                                     value.addEventListener
(Event.COMPLETE,
> completeHandler);
> 
>                                     
> 
>  
> value.addEventListener(RSLEvent.RSL_PROGRESS, rslProgressHandler);
> 
>  
> value.addEventListener(RSLEvent.RSL_COMPLETE, rslCompleteHandler);
> 
>  
> value.addEventListener(RSLEvent.RSL_ERROR, rslErrorHandler);
> 
>                                     
> 
>  
> value.addEventListener(FlexEvent.INIT_PROGRESS, 
initProgressHandler);
> 
>  
> value.addEventListener(FlexEvent.INIT_COMPLETE, FlexInitComplete);
> 
>                         }
> 
>         
> 
>                         private function FlexInitComplete
(event:Event):void
> 
>                         {
> 
>                                     
> 
>                                     var configRequest:URLRequest = 
new
> URLRequest("siteconfig.xml");
> 
>                                     var configLoader:URLLoader = new
> URLLoader(configRequest);
> 
>                                     
> 
>  
> configLoader.addEventListener("complete", configLoaded);
> 
>                                                                     
    
> 
>                                     //dispatchEvent(new
> Event(Event.COMPLETE)); 
> 
>                                     
> 
>                         }
> 
>                         
> 
>                         private function configLoaded(e:Event):void
> 
>                         {
> 
>                                     var appMain:Object =
> Application.application;
> 
>                                     
> 
>  
> appMain.appSettings.processConfig(e.currentTarget.data);
> 
>                                     
> 
>                                     dispatchEvent(new
> Event(Event.COMPLETE)); 
> 
>                         }
> 
>                         
> 
>             }
> 
> }
> 
>  
> 
> Giles Roadnight

Reply via email to