Jump to content
Search Community

How much time left before dowload is complete?

AdrianaBaron test
Moderator Tag

Recommended Posts

You could estimate the value using the loadTime and the progress. Kinda like:

 

var secondsLeft:Number = ((1 / myLoader.progress) - 1) * myLoader.loadTime;

 

This equation won't work if myLoader.progress is zero, though, so I'd recommend checking for that condition. You'd want to make sure that there's some progress made - the more progress, the more accurate the estimate will become.

Link to comment
Share on other sites

  • 1 month later...

I tried this code and my trace seems to be displaying the total time.... Am I doing something wrong?

 

function progressHandler(event:LoaderEvent):void 
{
if(queue.progress != 0)
{
	var secondsLeft:Number = (1 /queue.progress) * queue.loadTime;
	trace(int(secondsLeft));
}
}

trace result

4

5

5

5

5

5

5

5

5

5

5

 

THANKS!!!!!!!

Link to comment
Share on other sites

in case anyone is interested this is how I displayed the time left in 00:00 format

 

function progressHandler(evt:LoaderEvent):void 
{
//percentage loaded
var pcent:Number = Math.ceil((evt.target.progress)*100);
preLoader_mc.loading_txt.text = "loading photos - " + pcent + "%";

//time left
if(myLoaderMax.progress != 0)
{
	var secondsLeft:uint = Math.ceil(((1 / myLoaderMax.progress) - 1) * myLoaderMax.loadTime);
	var minsLeft:uint = secondsLeft/60
	var mins:String;
	if (minsLeft < 10)
	{
		mins = "0" + minsLeft.toString();
	}else{
		mins = minsLeft.toString();
	}
	secondsLeft %= 60;
	var secs:String;
	if  (secondsLeft < 10)
	{
		secs = "0" + secondsLeft.toString();
	}else
	{
		secs = secondsLeft.toString();
	}
	preLoader_mc.time_txt.text = "time left - " + mins + ":" + secs;
}
}

 

see it in action here...

http://www.nickbee.com/LoaderMax

Link to comment
Share on other sites

Very cool! Thanks for sharing.

 

By the way, you could probably simplify your code a bit, like this:

 

function progressHandler(evt:LoaderEvent):void {
  //percentage loaded
  var pcent:Number = int(evt.target.progress * 100);
  preLoader_mc.loading_txt.text = "loading photos - " + pcent + "%";

  //time left
  if (myLoaderMax.progress != 0) {
  var secondsLeft:Number = ((1 / myLoaderMax.progress) - 1) * myLoaderMax.loadTime;
  var mins:String = force2Digits(int(secondsLeft / 60));
  var secs:String = force2Digits(int(secondsLeft % 60));
  preLoader_mc.time_txt.text = "time left - " + mins + ":" + secs;
  }
}

function force2Digits(value:Number):String {
return (value }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...