Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

ProgressBar Component of Flash CS3

This is a discussion on ProgressBar Component of Flash CS3 within the Tutorials forums, part of the Flash English category; This is an article which could be a variant of these articles: Loading an external SWF with Flash CS3 Preloader ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 Flash CS4 > Flash English > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  5 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 27-09-07, 09:15
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
ProgressBar Component of Flash CS3

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
File Type: zip ProgressBar.zip (548.3 KB, 177 views)

__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !

Last edited by Flep; 28-08-08 at 07:02..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 28-10-08, 06:28
Junior Member
 
Join Date: Mar 2008
Posts: 1
Rep Power: 0
fahis is on a distinguished road
Re: ProgressBar Component of Flash CS3

thank you

how to do loading 3 external SWF file controlling with 3 button, loading bar
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-12-08, 18:35
Junior Member
 
Join Date: Dec 2007
Posts: 1
Rep Power: 0
me_myself is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
RadioButton component of Flash CS3 Flep Tutorials 1 05-08-08 09:52
The Slider component of Flash CS3 Flep Tutorials 14 07-07-08 23:41
Using NumericStepper - Flash CS3 component Flep Tutorials 1 09-02-08 18:12
ColorPicker - Flash CS3 Component Flep Tutorials 0 08-10-07 16:14
Componente ProgressBar di Flash CS3 Flep Articoli e tutorials 0 20-09-07 14:42


All times are GMT. The time now is 16:50.

Powered by vBulletin version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap