Ultrashock Forums > Flash > ActionScript
[AS3] Fake loader based on time

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
[AS3] Fake loader based on time
Old 2009-06-30

I can't seem to get the logic down correctly so I need some help Lets say I have a progress bar with a width of 300px. When I set the width/scaleX to zero, how can I increase the width/scaleX based on duration. So if I want the entire load progress to last three minutes, it will take the load bar three minutes to go from zero to either its maximum width (300px) or 100% scaleX?

PS: Using "width" or "scaleX" does not matter.

Thanks
I'm going to eat your brain and gain your knowledge.
postbit arrow 4 comments | 117 views postbit arrow Reply: with Quote   
Registered User
Isocase is offline
seperator
Posts: 1,411
2006-11-03
Age: 28
Isocase lives in United States
Isocase's Avatar
seperator

Ultrashock Member Comments:
tiran tiran is offline tiran lives in United States 2009-07-01 #2 Old  
Just get the percentage of time gone by and apply that percentage to the total width of your bar.

Calculate how much time has passed. Say 1 minute has gone by. Then you would find out the percentage that 1 minute is of 3 minutes (1 divided by 3). That would give you 0.33. Then all you need to do is times 300 by .33 and your load bar would need to be 99px. Might have to do some rounding in there when you actually tell your load bar how wide to be (so its not a decimal).
Reply With Quote  
Nutrox's Avatar Nutrox Nutrox is offline Super Moderator Nutrox lives in United Kingdom 17 Creative Assets 2009-07-01 #3 Old  
The value of the "percent" variable in the update() function will range from 0.0 to 1.0 inclusive, you can use that value as-is to scale a display object.

Code:
var timeStart:int = 0;
var timeTotal:int = 180000; // 3 minutes

startLoad();

function startLoad():void
{
	timeStart = getTimer();
	addEventListener( Event.ENTER_FRAME, update );
}

function update( e:Event ):void
{
	var percent:Number = ( getTimer() - timeStart ) / timeTotal;
	
	if( percent >= 1.0 )
	{
		percent = 1.0;
		removeEventListener( Event.ENTER_FRAME, update );
		
		// load complete
		trace( percent, "LOADED" );
	}
	else
	{
		// load progress
		trace( percent );
	}
	
	progressBar.setProgress( percent );
}
Reply With Quote  
Isocase's Avatar Isocase Isocase is offline Isocase lives in United States 2009-07-01 #4 Old  
Wonderful Nutrox!

In my original thinking I had an interval running every second updating a value and an eventListener to handle the progress. I didn't feel good about that solution that is why I posted
Reply With Quote  
Nutrox's Avatar Nutrox Nutrox is offline Super Moderator Nutrox lives in United Kingdom 17 Creative Assets 2009-07-01 #5 Old  
No problem man. Tiran hit the nail on the head with his reply, I just threw together a working example.
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: