optimize a download
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);
}