Skip to main content
Inspiring
December 28, 2021
Answered

multiple sounds preload

  • December 28, 2021
  • 1 reply
  • 277 views

Hello. I need to do multiple preload of mp3 files in the cloud. I have used the Blukloader class (it works for all types of files):

 

https://blog.unijimpe.net/precarga-multiple-en-as3/comment-page-1/?unapproved=330332&moderation-hash=c925fba9675d0353eddcad2f9058ca42#comment-330332

 

there  come the instructions on how the class is applied.

It works fine for external files (uploads multiple and can be controlled individually) but for cloud files it uploads the files, but when I try to play them it gives this error:

 

[BulkLoader] Failed to get content with url: 'berClav'as type: [class Sound]
TypeError: Error # 1009: Cannot access a property or method of a null object reference.

 

maybe you have to do some modification in the Bulkloader class to make it support files from the cloud.

I appreciate the help

    This topic has been closed for replies.
    Correct answer joaquin5EDD

    I have to add that I have already solved the multiple download of sound files in the cloud. this is the code i used and works fine !:

     

    import flash.net.URLLoader;
    import flash.display.Loader;
    import flash.events.ProgressEvent;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.net.URLRequest;
    import fl.controls.ProgressBar;
    import flash.media.Sound;
    import flash.events.StatusEvent;
    
    
    var img0:String = "https://www.googleapis.com/drive/v3/files/1P28gWUaVleErTfeXIdG6Iwwnag6ckJel?alt=media&key=AIzaSyA8luNvCKx9bnn4tCdtUoOp6jJ1OliH29Y";
    var img1:String = "https://www.googleapis.com/drive/v3/files/1elacmaqcQ7toteOIvIVtHu1tbeR5x7pN?alt=media&key=AIzaSyA8luNvCKx9bnn4tCdtUoOp6jJ1OliH29Y";
    var sound1:Sound;
    var sound2:Sound;
    var sound:Array = ["sound1","sound2"];
    var controlCarga_1: ProgressBar = new ProgressBar();
    
    controlCarga_1.width = 320;
    controlCarga_1.move(50, 40);
    addChild(controlCarga_1);
    
    
    for (var i:uint=0; i<2; i++) {
    	this[sound[i]] = new Sound();
    	controlCarga_1.source = this[sound[i]];
    	this[sound[i]].load (new URLRequest(this["img"+i]));
    	this[sound[i]].addEventListener(Event.COMPLETE, imagenCargada);
    	this[sound[i]].addEventListener(ProgressEvent.PROGRESS, imagenProgreso);
    	this[sound[i]].addEventListener(IOErrorEvent.IO_ERROR, onError);
    
    }
    
    function imagenProgreso(event:ProgressEvent):void {
    	formato_1.text = "Load..." + Math.floor(event.bytesLoaded / 1024) + "/" + Math.floor(event.bytesTotal / 1024) + "KB";
    	//trace("progressHandler: bytesLoaded=" + e.bytesLoaded + " bytesTotal=" + e.bytesTotal);
    }
    
    function imagenCargada(event:Event):void {
    	formato_1.text = "archivo cargado con éxito";
    	//removeChild(controlCarga_1);
    }
    
    
    function onError(event:IOErrorEvent):void {
    	trace("ioErrorHandler");
    }
    
    function play_music (e:MouseEvent):void{
    	sound1.play(0, 1000);
    	sound2.play(0, 1000);
    }
    play_button.addEventListener(MouseEvent.CLICK, play_music);

     

    The only thing this code does not allow me is removechild the loading bar when the load is finished (I don't know where to put removeChild (controCarga_1);

     

    the point is that it would be interesting to resolve the issue of the bulkloader class for future use by users on the network. It seems like a very flexible and useful class, but it has the flaw of not working with files in the cloud, but solving that is very difficult for me.

    Thanks for the help

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    December 28, 2021

    Hi.

     

    Do you mind showing the code so we can understand better what's going on?

     

    Regards,

    JC

    Inspiring
    December 29, 2021

    hello. my code is as follows. works fine with mp3 files external to animate, but does not work with cloud files (uploads files but does not sound):

     

    import br.com.stimuli.loading.BulkLoader;
    import br.com.stimuli.loading.BulkProgressEvent;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import fl.controls.ProgressBar;
    import flash.media.Sound;
    
    
    
    var loader:BulkLoader = new BulkLoader("mainLoader");
    loader.add("https://www.googleapis.com/drive/v3/files/1P28gWUaVleErTfeXIdG6Iwwnag6ckJel?alt=media&key=AIzaSyA8luNvCKx9bnn4tCdtUoOp6jJ1OliH29Y", {id: "berClav"});
    loader.add("https://www.googleapis.com/drive/v3/files/1elacmaqcQ7toteOIvIVtHu1tbeR5x7pN?alt=media&key=AIzaSyA8luNvCKx9bnn4tCdtUoOp6jJ1OliH29Y", {id: "berTiorb"});
    //loader.add("clave.mp3", {id: "berClav2"});
    //loader.add("tiorba.mp3", {id: "berTiorb2"});
    loader.addEventListener(BulkLoader.COMPLETE, onLoaded);
    loader.addEventListener(BulkLoader.PROGRESS, onProgress);
    loader.addEventListener(BulkLoader.ERROR, onError);
    loader.start();
    
    	var controlCarga_1:ProgressBar = new ProgressBar();
    	controlCarga_1.source = loader;
    	controlCarga_1.width = 320;
    	controlCarga_1.move(50, 40);
    	addChild(controlCarga_1);
    
    function onProgress(event:ProgressEvent): void{
    	formato_1.text = "Load..." + Math.floor(event.bytesLoaded / 1024) + "/" + Math.floor(event.bytesTotal / 1024) + "KB";
    	
    }
    
    function onLoaded(e: Event): void{
    	formato_1.text = "archivo cargado con éxito";
    
    
    	removeChild(controlCarga_1);
    }
    
    function onError(e:Event):void{
    	trace:("error de carga");
    }
    
    function play_music (e:MouseEvent):void{
    	var sonido:Sound = loader.getSound ("berClav");
    	sonido.play(0,1000);
    	var sonido2:Sound = loader.getSound ("berTiorb");
    	sonido2.play(0,1000);
    }
    
    
    play_button.addEventListener(MouseEvent.CLICK, play_music);

     

    In this link the classes that I use to do a multiple load are explained:

    https://blog.unijimpe.net/precarga-multiple-en-as3/

    there they explain how to use them. The link to the classes is this (it is included in the previous link):

    https://code.google.com/archive/p/bulk-loader/downloads

    I think the problem comes from the bulkloader class (I have not put it because it is very long and easy to locate in those links). this class allows to do multiple downloads with any file, but it does not allow me to do it if the files are in the cloud. it would be nice to solve that question, since the class is very interesting. Thanks a lot.

    joaquin5EDDAuthorCorrect answer
    Inspiring
    December 29, 2021

    I have to add that I have already solved the multiple download of sound files in the cloud. this is the code i used and works fine !:

     

    import flash.net.URLLoader;
    import flash.display.Loader;
    import flash.events.ProgressEvent;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.net.URLRequest;
    import fl.controls.ProgressBar;
    import flash.media.Sound;
    import flash.events.StatusEvent;
    
    
    var img0:String = "https://www.googleapis.com/drive/v3/files/1P28gWUaVleErTfeXIdG6Iwwnag6ckJel?alt=media&key=AIzaSyA8luNvCKx9bnn4tCdtUoOp6jJ1OliH29Y";
    var img1:String = "https://www.googleapis.com/drive/v3/files/1elacmaqcQ7toteOIvIVtHu1tbeR5x7pN?alt=media&key=AIzaSyA8luNvCKx9bnn4tCdtUoOp6jJ1OliH29Y";
    var sound1:Sound;
    var sound2:Sound;
    var sound:Array = ["sound1","sound2"];
    var controlCarga_1: ProgressBar = new ProgressBar();
    
    controlCarga_1.width = 320;
    controlCarga_1.move(50, 40);
    addChild(controlCarga_1);
    
    
    for (var i:uint=0; i<2; i++) {
    	this[sound[i]] = new Sound();
    	controlCarga_1.source = this[sound[i]];
    	this[sound[i]].load (new URLRequest(this["img"+i]));
    	this[sound[i]].addEventListener(Event.COMPLETE, imagenCargada);
    	this[sound[i]].addEventListener(ProgressEvent.PROGRESS, imagenProgreso);
    	this[sound[i]].addEventListener(IOErrorEvent.IO_ERROR, onError);
    
    }
    
    function imagenProgreso(event:ProgressEvent):void {
    	formato_1.text = "Load..." + Math.floor(event.bytesLoaded / 1024) + "/" + Math.floor(event.bytesTotal / 1024) + "KB";
    	//trace("progressHandler: bytesLoaded=" + e.bytesLoaded + " bytesTotal=" + e.bytesTotal);
    }
    
    function imagenCargada(event:Event):void {
    	formato_1.text = "archivo cargado con éxito";
    	//removeChild(controlCarga_1);
    }
    
    
    function onError(event:IOErrorEvent):void {
    	trace("ioErrorHandler");
    }
    
    function play_music (e:MouseEvent):void{
    	sound1.play(0, 1000);
    	sound2.play(0, 1000);
    }
    play_button.addEventListener(MouseEvent.CLICK, play_music);

     

    The only thing this code does not allow me is removechild the loading bar when the load is finished (I don't know where to put removeChild (controCarga_1);

     

    the point is that it would be interesting to resolve the issue of the bulkloader class for future use by users on the network. It seems like a very flexible and useful class, but it has the flaw of not working with files in the cloud, but solving that is very difficult for me.

    Thanks for the help