Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Results 1 to 4 of 4

Thread: ProgressBar Component of Flash CS3

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,609
    Rep Power
    9

    ProgressBar Component of Flash CS3

    flash templates
    This is an article which could be a variant of these articles:
    Loading an external SWF with Flash CS3
    Preloader with Flash CS3  and
    Preloader for beginners
    In this case, I use the ProgressBar component to monitor the loading state of an external SWF.
    Also, I use the IULoader component to load the SWF instead of the Loader class (used in many examples in this site) and a Label component instead of a dynamic text field.

    Let's see how it works'

    I create a FLA and save it as 'bar.fla', into which I drag a instance of the ProgressBar component and give it an name 'br_pb'.
    I create a Document Class, an ASfile saved as 'Main.as', implemented the following way:
    Code:
    package
    {
    	import flash.display.MovieClip;
    	import fl.containers.UILoader;
    	import fl.controls.Label;
    	import flash.text.TextFieldAutoSize;
    	import flash.events.Event;
    	import flash.events.ProgressEvent;
    	
    	public class Main extends MovieClip
    	{
    		private var UI_loader:UILoader
    		
    		private var etichetta:Label;
    		
    		private var url:String;
    		
    		public function Main()
    		{
    			init();
    		}
    		
    		private function init():void
    		{
    			url='http://www.flepstudio.org/swf/my_swf.swf'cachebuster='+new Date().getTime();
    			
    			UI_loader=new UILoader();
    			UI_loader.autoLoad=false;
    			UI_loader.source=url;
    			UI_loader.move(stage.stageWidth/2,stage.stageHeight/2);
    			UI_loader.scaleContent=false;
    			UI_loader.load();
    			
    			bar_pb.source=UI_loader;
    			bar_pb.move(stage.stageWidth/2-bar_pb.width/2,stage.stageHeight/2);
    			bar_pb.addEventListener(ProgressEvent.PROGRESS,progresso);
    			bar_pb.addEventListener(Event.COMPLETE,completato);
    			
    			etichetta=new Label();
    			etichetta.autoSize=TextFieldAutoSize.LEFT;
    			etichetta.move(bar_pb.x,bar_pb.y+bar_pb.height);
    			addChild(etichetta);
    		}
    		
    		private function progresso(e:ProgressEvent):void 
    		{
    			etichetta.text=int(e.currentTarget.percentComplete)+'%';
    		}
    		
    		private function completato(e:Event):void 
    		{
    			bar_pb.removeEventListener(ProgressEvent.PROGRESS,progresso);
    			bar_pb.removeEventListener(Event.COMPLETE,completato);
    			
    			removeChild(bar_pb);
    			removeChild(etichetta);
    			addChild(UI_loader);
    			
    			UI_loader.move(-100,-100);
    		}
    	}
    }
    The result:







    Let's analise the code.

    Properties

    an instance of the UILoader component
    private var UI_loader:UILoader
    an instance of the Label component
    private var etichetta:Label;
    a string variable containing the URL of the external SWF
    private var url:String;

    Methods
    init();
    I assign the external SWF url to the variable 'url'
    url='http://www.flepstudio.org/swf/my_swf.swf'cachebuster='+new Date().getTime();
    I create an instance of UILoader component
    UI_loader=new UILoader();
    I impost its autoLoad property to false
    UI_loader.autoLoad=false;
    I assign to its source property, the value of the variable 'url'
    UI_loader.source=url;
    I position the component
    UI_loader.move(stage.stageWidth/2,stage.stageHeight/2);
    I impost its scaleContent property to false
    UI_loader.scaleContent=false;
    I start the loading of the external SWF
    UI_loader.load();
    I tell the ProgressBar that its source property is the instance of UILoader
    bar_pb.source=UI_loader;
    I position the ProgressBar
    bar_pb.move(stage.stageWidth/2-bar_pb.width/2,stage.stageHeight/2);
    I add a listener to the ProgressBar to the ProgressEvent.PROGRESS, which will call the function progresso()
    bar_pb.addEventListener(ProgressEvent.PROGRESS,pro gresso);
    I add a listener to the ProgressBar to the Event.COMPLETE, which will call the function completato()
    bar_pb.addEventListener(Event.COMPLETE,completato) ;
    I create an instance of the Label component
    etichetta=new Label();
    I assign an autosize, using the static method LEFT of the TextFieldAutoSize class
    etichetta.autoSize=TextFieldAutoSize.LEFT;
    I position the Label
    etichetta.move(bar_pb.x,bar_pb.y+bar_pb.height);
    I add it to the DisplayObject (otherwise it would not be visible)
    addChild(etichetta);



    progresso();
    I assign the text to the Label component. In this case, the percentComplete property of the ProgressBar
    etichetta.text=int(e.currentTarget.percentComplete )+'%';

    completato();
    I remove the listeners
    bar_pb.removeEventListener(ProgressEvent.PROGRESS, progresso);
    bar_pb.removeEventListener(Event.COMPLETE,completa to);
    I remove the ProgressBar and Label components
    removeChild(bar_pb);
    removeChild(etichetta);
    I add to the DisplayObject the instance of the UILoader which now contains the external SWF and is a MovieClip
    addChild(UI_loader);
    I position the instance of UILoader
    UI_loader.move(-100,-100);

    Source files:
    Attached Files

  2. #2
    Junior Member Settled In fahis is on a distinguished road
    Join Date
    Mar 2008
    Posts
    1
    Rep Power
    0

    Re: ProgressBar Component of Flash CS3

    thank you

    how to do loading 3 external SWF file controlling with 3 button, loading bar

  3. #3
    Junior Member Settled In me_myself is on a distinguished road
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Re: ProgressBar Component of Flash CS3

    The code in the zip file is different from the one posted in the article !! The first line reads "var myRequest:URLRequest = new URLRequest("large_image.jpg");" - how do i load my swf file (play next frame) after the preloader? Thanks

  4. #4
    Junior Member Settled In mindmadness is on a distinguished road
    Join Date
    Aug 2009
    Posts
    1
    Rep Power
    0

    Re: ProgressBar Component of Flash CS3

    Any chance of a resizing script that resizes the loaded content to the same size as the stage?

+ Reply to Thread

LinkBacks (?)

  1. 09-09-08, 18:10
  2. 04-04-08, 00:46
  3. 31-03-08, 12:24
  4. 27-03-08, 13:20
  5. 05-02-08, 17:04

Similar Threads

  1. Replies: 89
    Last Post: 01-05-10, 15:02
  2. The Slider component of Flash CS3
    By Flep in forum Tutorials
    Replies: 16
    Last Post: 04-02-09, 11:07
  3. Using NumericStepper - Flash CS3 component
    By Flep in forum Tutorials
    Replies: 1
    Last Post: 09-02-08, 17:12
  4. ColorPicker - Flash CS3 Component
    By Flep in forum Tutorials
    Replies: 0
    Last Post: 08-10-07, 15:14
  5. Componente ProgressBar di Flash CS3
    By Flep in forum Articoli e tutorials
    Replies: 0
    Last Post: 20-09-07, 13:42

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts