• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

optimize a download

Contributor ,
Apr 12, 2022 Apr 12, 2022

Copy link to clipboard

Copied

Hello. I have this code where I download 54 (short) sound files. I also have a button that, while downloading, you can go back (in case the user has made the wrong file)

when I start downloading a group of files and hit the back button and then re-download the same group of files, the load is considerably faster!! (I do not know why!)

Is there a way to optimize this download so that it goes fast also the first time I hit it?

Thank you very much!

 

function load_soundsF():void{
	i = current_index;
	this[soundZ[i]] = new Sound();
	this[soundZ[i]].load (new URLRequest(this[Data.so.data.sound+i]));
	pantallaCarga.progressNumber.text=i + " / 54";
	pantallaCarga.carga_text.text = "Cargando "+ Data.so.data["sound"].split("_").join(" ")+"....";

	this[soundZ[i]].addEventListener(IOErrorEvent.IO_ERROR, onError);
	this[soundZ[i]].addEventListener(Event.COMPLETE, imagenCargada);
	
	function onError(event:IOErrorEvent):void {
		trace("ioErrorHandler");
		dispatchEvent(errorA);
	}
	function imagenCargada(event:Event):void{

	// load progress has advanced another 1/54th. update your loadbar.
		current_index++;

		if(current_index<54){
			load_soundsF();
		}
		else {
			//pantallaCarga.formato_1.text = Data.so.data["sound"].split("_").join(" ")+" cargado con exito";
			pantallaCarga.gotoAndStop(1);
		}

	}
}

pantallaCarga.back_button.addEventListener(MouseEvent.MOUSE_DOWN,back_home);

private function back_home(e:MouseEvent):void{
	dispatchEvent(backE);
}

Views

147

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 12, 2022 Apr 12, 2022

Copy link to clipboard

Copied

I managed to speed up the download with this code. The issue was that calling the download function several times (before the download finished) speeded up this download. so I've called it multiple times in a loop, like so:

for (var j:uint=0; j<5; j++) {
	load_soundsF();
}


function load_soundsF():void{
	i = current_index;
	this[soundZ[i]] = new Sound();
	this[soundZ[i]].load (new URLRequest(this[Data.so.data.sound+i]));
	pantallaCarga.progressNumber.text=i + " / 54";
	pantallaCarga.carga_text.text = "Cargando "+ Data.so.data["sound"].split("_").join(" ")+"....";

	this[soundZ[i]].addEventListener(IOErrorEvent.IO_ERROR, onError);
	this[soundZ[i]].addEventListener(Event.COMPLETE, imagenCargada);
	
	function onError(event:IOErrorEvent):void {
		trace("ioErrorHandler");
		dispatchEvent(errorA);
	}
	function imagenCargada(event:Event):void{

	// load progress has advanced another 1/54th. update your loadbar.
		current_index++;

		if(current_index<54){
			load_soundsF();
		}
		else {
			//pantallaCarga.formato_1.text = Data.so.data["sound"].split("_").join(" ")+" cargado con exito";
			pantallaCarga.gotoAndStop(1);
		}

	}
}

pantallaCarga.back_button.addEventListener(MouseEvent.MOUSE_DOWN,back_home);

private function back_home(e:MouseEvent):void{
	dispatchEvent(backE);
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

LATEST

Telling a browser to download the same file multiple times does NOT magically make it download faster. If your downloads seemed to run faster after interrupting it, that's probably because it had cached the files it had already downloaded.

 

However, it is sometimes possible to make downloads of many files faster by dispatching several download requests in parallel, so it's possible this is what your nightmarish solution is accidentally doing.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines