Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
doodledude

LoaderMax: estimatedbytes

Recommended Posts

Hi Jack,

 

beyond hardcoding 'estimatedbytes' have you tried using URLStream to retrieve the file's totalBytes prior to doing the actual load using the correct/relevent flash loading class?

 

Unlike the Loader and URLLoader classes URLStream can be cancelled immediatley with no further loading overhead which means its great for optaining this information, and the time that this quick request takes even on a larger queue is all but unnoticable!

 

The simpleset way i've found in my development is where you set the url to be loaded (in the constructor), start a URLStream, then use the onprogress event to get the totalbytes (evt["bytesTotal"]). Save that information and immediately cancel the URLStream, marking the loader's state as ready. This would also need to be handled in the URLStream's oncomplete event in case it's a very small file loading on a fast connection.

 

For individual loads this maybe isn't of great use so could be turned on and off via a preloadTotalBytes:Boolean variable in the constructor,

but where you have a queue to load (LoaderMax), you can loop through all its internal loaders to check their totalbytes before beginning the load or displaying a preload graphic.

 

here's a quick rendition if you've not already looked into it:

public loaderconstructor(fileURL, preloadBytesTotal:Boolean=false){
_file = fileURL;
if(preloadBytesTotal){
	getFileInfo();
}else{
	_readyToLoad = true;
}
}

protected function getFileInfo():void{
_fileInfoStream = new URLStream();
_fileInfoStream.addEventListener(ProgressEvent.PROGRESS, getFileInfoProgress, false, 0, true);
_fileInfoStream.addEventListener(Event.COMPLETE, getFileInfoProgress, false, 0, true);
_fileInfoStream.addEventListener(IOErrorEvent.IO_ERROR, getFileInfoError, false, 0, true);
_fileInfoStream.addEventListener(SecurityErrorEvent.SECURITY_ERROR, getFileInfoError, false, 0, true);
_fileInfoStream.load(new URLRequest(_file));
}

protected function getFileInfoProgress(e:*):void {
_bytesTotal = e["bytesTotal"];
_fileInfoStream.close();
removeEventListeners();
_fileInfoStream = null;
_readyToLoad = true;
}

protected function getFileInfoError(e:*):void {
removeEventListeners();
try{ _fileInfoStream.close(); }catch(e:*){};
_fileInfoStream = null;
/*
you could dipatch/report the error, but as this is a hidden process and given that at this point the developer may not have called the load() method to start the real load, it may be better to dismiss/subdue it for now and let the error happen again during the real load to be reported and handled at that time.
*/
_readyToLoad = true;
}

public function load(){
/*
based on my scenario of not reporting the error in getFileInfoError()
*/
if (!_readyToLoad){
	start a timer to check till its true
}else{
	do the real load
}
}

Link to comment
Share on other sites

Great idea. I still prefer the estimatedBytes technique because it maximizes performance but I can definitely see some situations where developers won't want to set estimatedBytes for things (or can't know it). In the latest post of LoaderMax, I added a "auditSize" special property for LoaderMax along with an auditSize() method for all loaders. If auditSize is true for a LoaderMax, it will loop through all its children and if any do NOT have an estimatedSize explicitly defined, it will audit the size by opening up a URLStream as you suggested.

 

I set the default value of auditSize to false because I don't want to create extra network traffic or slowdowns (even if they're relatively small) unless the user explicitly requests it, but I'd be curious what others think.

 

Snag the latest version in your GreenSock account. https://www.greensock.com/account/ and let me know if it works well for you.

Link to comment
Share on other sites

Excellent idea 8-)

 

set the default value of auditSize to false because I don't want to create extra network traffic

First goal the performance... Great !

 

Thanks a lot ;)

Link to comment
Share on other sites

+ 1 for this feature

 

Yep, it's already in there. auditSize:true. :)

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.
×