Can Actionscript load client side .wav files?

  • janice_2k
  • Novice
  • Novice
  • janice_2k
  • Posts: 28

Post 3+ Months Ago

Dear Gurus and members,
I am a newbie in Flash MX 2004 and Actionscript. Can Actionscript call and playback .wav files that are stored on the user's pc? Is there any way to do so? Is Actionscript server or client side scripting? I am at total lost. :cry: Any codes or suggestions are highly appreciated. Hope to hear seom reply soon.

Thanks in advance,
Janice
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

No, unfortunately Flash can only dynamically load in .mp3 files.
  • OriginNO
  • Graduate
  • Graduate
  • User avatar
  • Posts: 137
  • Loc: the Glass City (Hometown: the NO)

Post 3+ Months Ago

Hey Lost, how do you dynamically load mp3's. Is it anything like importing text files, and does it work with flash mp3's.
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

http://www.kennybellew.com/tutorial/

^^^ that tutorial has everything you ever need/want to know about the Sound() object in Flash. Including how to load in an external .mp3 file.
  • Ami
  • Newbie
  • Newbie
  • Ami
  • Posts: 6
  • Loc: Malaysia

Post 3+ Months Ago

hi,lost in beta . i ady try the tutorial which i need. what i done is a btn that can press then the sound will load. how about if i want another sound to be load after my second press on the btn n of course the first sound which load just now will stop.

at the first frame:
Code: [ Select ]
firstSound=new Sound();
firstSound.attachSound("firstSound01.wav");
  1. firstSound=new Sound();
  2. firstSound.attachSound("firstSound01.wav");


at the btn's action
Code: [ Select ]
on (press) { _root.firstSound.start() }


the code above can allow me to pree the btn n the firstSound01 will load.
  • Shandain
  • Born
  • Born
  • Shandain
  • Posts: 1
  • Loc: Wisconsin, USA

Post 3+ Months Ago

Hi ~ If I understand what you want to deo, you want a second sound to load the second time you press the button? You could use a variable to track how many times the user has pressed the button and just check that variable when you determine which sound to load.
Code: [ Select ]
on(press){
 switch(mycounter){
  case 0:
    //load sound 1
    break;
  case 1:
    //load sound 2
    break;
  case 2:
    //load sound 3
    break;
  case default:
    //load sound 4
    break;
 }
 mycounter++
}
  1. on(press){
  2.  switch(mycounter){
  3.   case 0:
  4.     //load sound 1
  5.     break;
  6.   case 1:
  7.     //load sound 2
  8.     break;
  9.   case 2:
  10.     //load sound 3
  11.     break;
  12.   case default:
  13.     //load sound 4
  14.     break;
  15.  }
  16.  mycounter++
  17. }

and you could add however many sounds you wanted that way...
  • Ami
  • Newbie
  • Newbie
  • Ami
  • Posts: 6
  • Loc: Malaysia

Post 3+ Months Ago

thanks .......

but what to write at the load sound there???

i put loadSound.firstSound01 izzit correct??? i don't know how to write the load sound there...........

please tell me how
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

As lostinbeta mentioned before, You can only load MP3 sounds at runtime.

With attachSound() the sound must be in the library of the FLA & properly linked for export when the movie is published, you wont be loading anything at runtime with attachSound(). Instead you will be creating thoose sound objects during authoring & using soundObj.start() to play them at runtime.

I'll go ahead & walk through an example of both attachSound & loadSound.

First, attachSound() (I noticed it being used earlier)

For example sake drag an instance of the button component to the stage & give it the instanceName "boomBox" Leave the clickHandeler blank.

Now with the button still selected open the actions panel (should say "Actions - Movie Clip")

Apply theese actions,
Code: [ Select ]
on(press){
    (played == undefined) ? played=0 : null;
    _root.sOA[played].stop();
    (played >= _root.totalSounds) ? played=1 : played++;
    _root.sOA[played].start();
}
  1. on(press){
  2.     (played == undefined) ? played=0 : null;
  3.     _root.sOA[played].stop();
  4.     (played >= _root.totalSounds) ? played=1 : played++;
  5.     _root.sOA[played].start();
  6. }


Now you may be wondering WTH is _root.sOA[played] ?? Well we'll get into that shortly, for now lets focus on what is happening here.

First there is (played == undefined) ? played=0 : null; This says "if the counter we are going to use to keep track is undefined, then make it"

Next there's _root.sOA[played].stop(); This tells all sounds that are playing to stop, It will effect other sounds playing in the movie but for example sake it serves out purpose. :wink:

Now we have (played >= _root.totalSounds) ? played=1 : played++; This looks at the total sounds variable that we will setup later, if played is greater than or equil to total sounds it resets the counter, otherwise it increments it by 1.

Finally for the button we have _root.sOA[played].start(); This tells the soundObject with the same array index as "played" to start playing.

Ok done with button actions, on to what goes in the root.
Click the dropdown menu right below where it says "Actions - Movie Clip" (what your looking for should say "Actions for boomBox (pushbutton)") & select what should be the other only option there ("Actions for Frame 1 of Layer Name Layer 1") Look at that no more clicking timelines or objects to switch actions panels :wink:

Ok now apply theese actions,
Code: [ Select ]
totalSounds = 4;
sOA = ["soundArray"];
for(i=1; i<=totalSounds; i++){
    sOA[i] = new Sound(boomBox);
}
// attach sounds from library to the objects
sOA[1].attachSound("sound1");
sOA[2].attachSound("sound2");
sOA[3].attachSound("sound3");
sOA[4].attachSound("sound4");
  1. totalSounds = 4;
  2. sOA = ["soundArray"];
  3. for(i=1; i<=totalSounds; i++){
  4.     sOA[i] = new Sound(boomBox);
  5. }
  6. // attach sounds from library to the objects
  7. sOA[1].attachSound("sound1");
  8. sOA[2].attachSound("sound2");
  9. sOA[3].attachSound("sound3");
  10. sOA[4].attachSound("sound4");


For the play by play we start with "totalSounds = 4;" , This is the sounds variable we talked about before.

Next we have sOA = ["soundArray"]; this is declaring an array to hold our sound objects. ("soundArray" is a personal naming scheeme :wink: )

Now for setting up out array of soundObjects we have this loop,
Code: [ Select ]
for(i=1; i<=totalSounds; i++){
    sOA[i] = new Sound(boomBox);
}
  1. for(i=1; i<=totalSounds; i++){
  2.     sOA[i] = new Sound(boomBox);
  3. }

All this loop does is fill our sOA with blank soundObjects that are attached to our boomBox button.

Ok on to assigning sounds to our sound objects in our sound object array.
we have
Code: [ Select ]
sOA[1].attachSound("sound1");
sOA[2].attachSound("sound2");
sOA[3].attachSound("sound3");
sOA[4].attachSound("sound4");
  1. sOA[1].attachSound("sound1");
  2. sOA[2].attachSound("sound2");
  3. sOA[3].attachSound("sound3");
  4. sOA[4].attachSound("sound4");

This attaches sounds from the library to each soundObject in out array, Now you may be saying "I dont see any .wav or .mp3" well that's becouse you dont really need it, now before you try excluding the extension from every sound and wondering why it's not working let me explain linking sounds in the library.

First we go to "File" then "Import to Library" and pick what sounds we want to add (hold CTRL to import multiple :wink: )

Now If it's not visible allready press F11 to bring up the library window.
You should see your sounds in there ready to be linked.

Here's how you link them,
Right click a sound & select "linkage", this will bring up a dialog with 3 checkboxes you can pick, check the one that says "Export for Actionscript" this will enable the "Identifier" box (where you put "sound1", "sound2", ect...I like to think of it as giving sounds in the library instanceNames) It will also enable a checkbox saying "Export in first frame" Leave it checked.

Provided you linked the sounds in the library correctly you should now be able to test the movie and get a new sound for each button press.


Now on to loading MP3 sounds.

This is going to be easier than you think, For the only big thing we have to change is the lines that fill our soundObject array :wink:

Where sOA[1].attachSound("sound1"); now becomes sOA[1].loadSound("url_to_MP3", false); where "false" tells the sound not to start unless actionscript tells it to. "url_to_mp3" should explain itself.

Keep in mind that theese sounds will not play if they are not fully downloaded, you may want to setup a preloader that enables the button only after all sounds have finished loading.

Well that should be enough to get some people started :D
  • janice_2k
  • Novice
  • Novice
  • janice_2k
  • Posts: 28

Post 3+ Months Ago

Hi guys,
My project requires me to create a button that will playback both server and client side mp3s alternately. I found a suggestion that says the following code will work. However after I tried, it didn't work at all. I am using actionscript 1.0.
Code: [ Select ]
_global.nameCount = 1;
_global.soundOrigin = 0;

_global.soundFileLoader = function() {
if(_global.nameCount <= 3){  // using 3 Questions and Answers
    if(_global.soundOrigin == 0){
        fileName = "PE14_1d" + _global.nameCount + ".mp3";
        stopAllSounds();
        mySound = new Sound();
        mySound.attachSound("fileName"); //server object
        _global.soundOrigin = 1;
      mySound.onSoundComplete = function(){
        _global.soundFileLoader();
      }
    }else{
      fileName = "test" + _global.nameCount + ".mp3";
        stopAllSounds();
        mySound = new Sound();
        mySound.loadSound("file:///c:/program files/sound recorder/" + fileName, true); // client file path
        _global.soundOrigin = 0;
        _global.nameCount ++;
      mySound.onSoundComplete = function(){
        _global.soundFileLoader();
      }
    }
  }
}
  1. _global.nameCount = 1;
  2. _global.soundOrigin = 0;
  3. _global.soundFileLoader = function() {
  4. if(_global.nameCount <= 3){  // using 3 Questions and Answers
  5.     if(_global.soundOrigin == 0){
  6.         fileName = "PE14_1d" + _global.nameCount + ".mp3";
  7.         stopAllSounds();
  8.         mySound = new Sound();
  9.         mySound.attachSound("fileName"); //server object
  10.         _global.soundOrigin = 1;
  11.       mySound.onSoundComplete = function(){
  12.         _global.soundFileLoader();
  13.       }
  14.     }else{
  15.       fileName = "test" + _global.nameCount + ".mp3";
  16.         stopAllSounds();
  17.         mySound = new Sound();
  18.         mySound.loadSound("file:///c:/program files/sound recorder/" + fileName, true); // client file path
  19.         _global.soundOrigin = 0;
  20.         _global.nameCount ++;
  21.       mySound.onSoundComplete = function(){
  22.         _global.soundFileLoader();
  23.       }
  24.     }
  25.   }
  26. }


On the button, my code is
Code: [ Select ]
on(release){  
  _global.soundFileLoader();
}
  1. on(release){  
  2.   _global.soundFileLoader();
  3. }


I used attachSound to make the object/mp3 on the server side work. While on the client's side, I used loadSound. However, it does not work. Any suggestions? Looking forward to some replies soon.

Thanks in advance,
Janice
  • janice_2k
  • Novice
  • Novice
  • janice_2k
  • Posts: 28

Post 3+ Months Ago

Hi there,
I changed the codes I sent previously on the button. All scriptings are done on the button itself without refering to the first frame. It works, however there are some bugs that I am not sure how to solve. The following is the code that works quite fine:

Code: [ Select ]
on(release){  
    var iddiscussion = 1;
    var numberFile = 4;
        
    function discussion() {
        server = new Sound();
        server.attachSound("PE14_1d"+iddiscussion+".mp3"); //server side mp3
        server.start(0, 0);
        server.onSoundComplete = function () {
            client = new Sound();
            client.loadSound("file:///c:/program files/sound recording/audiorecorder/test"+iddiscussion+".mp3", true); // client side mp3 files
            client.onLoad = function(success) {
                this.start();
            }
            client.onSoundComplete = function () {
                iddiscussion++;
                if (iddiscussion < numberFile) {
                discussion();
                }
            }
        }
    }
discussion();
}
  1. on(release){  
  2.     var iddiscussion = 1;
  3.     var numberFile = 4;
  4.         
  5.     function discussion() {
  6.         server = new Sound();
  7.         server.attachSound("PE14_1d"+iddiscussion+".mp3"); //server side mp3
  8.         server.start(0, 0);
  9.         server.onSoundComplete = function () {
  10.             client = new Sound();
  11.             client.loadSound("file:///c:/program files/sound recording/audiorecorder/test"+iddiscussion+".mp3", true); // client side mp3 files
  12.             client.onLoad = function(success) {
  13.                 this.start();
  14.             }
  15.             client.onSoundComplete = function () {
  16.                 iddiscussion++;
  17.                 if (iddiscussion < numberFile) {
  18.                 discussion();
  19.                 }
  20.             }
  21.         }
  22.     }
  23. discussion();
  24. }


My current problem is that if either one of the mp3 files does not exist, an error message will prompt and it will terminate the functions. Is there a method to make it proceed to the following mp3s eventhough it detects the file that is not existed? For example: After playing PE14_1d2.mp3 (server side), it should play test2.mp3(client side) and proceed to PE14_1d3.mp3 (server side) after that. If test2.mp3 does not exist, the PE14_1d2.mp3 will proceed to PE14_1d3.mp3 without any errors. I would be very glad if someone could guide me as I am at total lost. Looking forward to some replies soon.

Thanks in advance,
Janice
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Add the actions for the onSoundComplete to an if/else statement inside the onLoad checking for success of loading,
Code: [ Select ]
client.onLoad = function(success) {
    if(success){
        this.start();
    }else{
        iddiscussion++;
        if (iddiscussion < numberFile) {
            discussion();
        }
    }
}
  1. client.onLoad = function(success) {
  2.     if(success){
  3.         this.start();
  4.     }else{
  5.         iddiscussion++;
  6.         if (iddiscussion < numberFile) {
  7.             discussion();
  8.         }
  9.     }
  10. }

If the sound is loaded success returns true, else it returns false.
If success returns true proceed as normal, if success returns false then proceed as if client has finished playing.
  • janice_2k
  • Novice
  • Novice
  • janice_2k
  • Posts: 28

Post 3+ Months Ago

Hi Joebert,
Thanks for your reply. I tried your method. However, when I test movie, I saw an error on the output. The following is the code I wrote:
Code: [ Select ]
on(release){
var iddiscussion = 1;
var numberFile = 3;

function discussion() {
  server = new Sound();
  serverFile = "PE14_1d"+iddiscussion+".mp3";
  server.attachSound(serverFile);         //server side mp3
  server.start(0, 0);
  server.onSoundComplete = function () {
    client = new Sound();
    clientFile ="file:///c:/program files/sound recording/audiorecorder/test"+iddiscussion+".mp3";
    client.onLoad = function(success){    //define conditions for success first
     if(success){
       this.start();
     }else{                        //skip to the next file
       if(iddiscussion < numberFile) {    //no longer dependent on client.onSoundComplete
          iddiscussion++;
          discussion();
       }
     }
    }
    client.loadSound(clientFile, true);    //load client mp3
    client.onSoundComplete = function () {  //doesn't run if not success...
      if(iddiscussion < numberFile) {   
        iddiscussion++;
          discussion();
          }
    }
   
  }
}
discussion();

}
  1. on(release){
  2. var iddiscussion = 1;
  3. var numberFile = 3;
  4. function discussion() {
  5.   server = new Sound();
  6.   serverFile = "PE14_1d"+iddiscussion+".mp3";
  7.   server.attachSound(serverFile);         //server side mp3
  8.   server.start(0, 0);
  9.   server.onSoundComplete = function () {
  10.     client = new Sound();
  11.     clientFile ="file:///c:/program files/sound recording/audiorecorder/test"+iddiscussion+".mp3";
  12.     client.onLoad = function(success){    //define conditions for success first
  13.      if(success){
  14.        this.start();
  15.      }else{                        //skip to the next file
  16.        if(iddiscussion < numberFile) {    //no longer dependent on client.onSoundComplete
  17.           iddiscussion++;
  18.           discussion();
  19.        }
  20.      }
  21.     }
  22.     client.loadSound(clientFile, true);    //load client mp3
  23.     client.onSoundComplete = function () {  //doesn't run if not success...
  24.       if(iddiscussion < numberFile) {   
  25.         iddiscussion++;
  26.           discussion();
  27.           }
  28.     }
  29.    
  30.   }
  31. }
  32. discussion();
  33. }


It works fine and will not terminate when one of the mp3 at client side (example: test2.mp3 is deleted from the client's computer) does not exist. It will proceed to the following mp3 files smoothly. However, there is an error displayed when I tested the movie. The error was "Error opening URL "file:///c:/program files/sound recording/audiorecorder/test2.mp3". I wonder is there any ways to solve this?

I would be glad if you could guide me. Looking forward to some replies soon.

Thanks in advance,
Janice
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Janice_2k,
The only things I can think of are, A: The file doesnt exist, Or B: A problem with running the movie from the same computer that the loadSound("file:///...") is accessing.

Try placing the client side MP3s on the computer you've been working from in the directory where flash would look for them, then save the FLA on a different computer on the network & testing the movie like that. (FLA will be saved on compA, you will edit & test from compB, client mp3s will be on compB)
  • janice_2k
  • Novice
  • Novice
  • janice_2k
  • Posts: 28

Post 3+ Months Ago

Hi Joebert,
I have did some testing like your suggested method.It works fine when all mp3 files exist in the client's computer. What I am facing is an error occurs when the client's computer does not have a specific file, example, test2.mp3.

When the code found the file does not exist, it skips and continues to the proceeding file, in my case, it would play the following server side sound object. Currently, my code can play the proceeding file. However, there is an error msg displayed when I tested the movie. The error is something like this: "Error opening URL "file:///c:/program files/sound recording/audiorecorder/test2.mp3". Then, it continues playing the proceeding sound files smoothly. Hope its not confusing.

Looking forward to your reply soon.

Thanks in advance,
Janice
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

If everything is playing smoothly & your only worried about what that error means then you really have nothing to worry about.

That is Flash's debugger making sure you know the file doesn't exist in case it's a code error, it only happens when you test movie, in a browser that will be interpreted as returning false for the onLoad and nothing more.
  • janice_2k
  • Novice
  • Novice
  • janice_2k
  • Posts: 28

Post 3+ Months Ago

Thanks Joebert for your information. As I still can't upload to the server due to some problems, I was worried about the outcome on the browser when I saw the output in the test movie. Anyway, its a relieve to hear that. Thank you so much and have a nice day. :)

Thanks,
Janice
  • janice_2k
  • Novice
  • Novice
  • janice_2k
  • Posts: 28

Post 3+ Months Ago

Hi joebert,
I am trying to swap the codes mentioned in previous messages to calling client side mp3 first, then only play server side sound object. For example, it plays ClientAudio1.mp3 - serverAudio1, ClientAudio2.mp3 - serverAudio2, ClientAudio3.mp3 - serverAudio3 ... etc. However, I have no idea how could I 'swap' the functions. The following is the code that plays server side audio first before playing the client side mp3. Hope you could help me in swapping the scripts:

Code: [ Select ]
on (release) {
    stopAllSounds();
    var iddiscussion = 1;
    var numberFile = 3;
    var serverCtr = 0;
    var serverAudio = new Array("PE14_1a", "PE14_1c", "PE14_1e");
    function discussion() {
        server = new Sound();
        serverFile = serverAudio[serverCtr];
        server.attachSound(serverFile);
        server.start(0, 0);
        trace("SERVER "+serverFile+iddiscussion);
        server.onSoundComplete = function() {
            client = new Sound();
            clientFile = "file:///c:/program files/IEBAudioRecorder/test"+iddiscussion+".mp3";
            client.onLoad = function(success) {
                //define conditions for success first
                if (success) {
                    this.start();
                    client.onSoundComplete = function() {
                        if (iddiscussion<numberFile) {
                            iddiscussion++;
                            trace("Add counter to "+iddiscussion);
                            serverCtr++;
                            discussion();
                        }
                    };
                } else {
                    //skip to the next file
                    trace("SOUND FAILED!!!");
                    if (iddiscussion<numberFile) {
                        iddiscussion++;
                        trace("Add counter to "+iddiscussion);
                        serverCtr++;
                        discussion();
                    }
                }
            };
            client.loadSound(clientFile, true);
        };
    }
    discussion();
}
  1. on (release) {
  2.     stopAllSounds();
  3.     var iddiscussion = 1;
  4.     var numberFile = 3;
  5.     var serverCtr = 0;
  6.     var serverAudio = new Array("PE14_1a", "PE14_1c", "PE14_1e");
  7.     function discussion() {
  8.         server = new Sound();
  9.         serverFile = serverAudio[serverCtr];
  10.         server.attachSound(serverFile);
  11.         server.start(0, 0);
  12.         trace("SERVER "+serverFile+iddiscussion);
  13.         server.onSoundComplete = function() {
  14.             client = new Sound();
  15.             clientFile = "file:///c:/program files/IEBAudioRecorder/test"+iddiscussion+".mp3";
  16.             client.onLoad = function(success) {
  17.                 //define conditions for success first
  18.                 if (success) {
  19.                     this.start();
  20.                     client.onSoundComplete = function() {
  21.                         if (iddiscussion<numberFile) {
  22.                             iddiscussion++;
  23.                             trace("Add counter to "+iddiscussion);
  24.                             serverCtr++;
  25.                             discussion();
  26.                         }
  27.                     };
  28.                 } else {
  29.                     //skip to the next file
  30.                     trace("SOUND FAILED!!!");
  31.                     if (iddiscussion<numberFile) {
  32.                         iddiscussion++;
  33.                         trace("Add counter to "+iddiscussion);
  34.                         serverCtr++;
  35.                         discussion();
  36.                     }
  37.                 }
  38.             };
  39.             client.loadSound(clientFile, true);
  40.         };
  41.     }
  42.     discussion();
  43. }


Looking forward to some replies soon.

Thanks in advance,
Janice
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

If I read this right you want to load one sound from client side, then loop through the list of attachable server sounds once client completes.

I tried to keep this as close to the original as possible :)
Code: [ Select ]
on (release) {
  stopAllSounds();
  var iddiscussion = 1; /*This needs to reflect the number in the name of the client sound, it will be assigned a value of "false" once client is done with. */
  var numberFile = 3;
  var serverCtr = 0;
  var serverAudio = new Array("PE14_1a", "PE14_1c", "PE14_1e");
  function discussion() {
      if(iddiscussion){
              clientFile = "file:///c:/program files/IEBAudioRecorder/test"+iddiscussion+".mp3";
            client = new Sound(this);
            client.onLoad = function(success){
                if(success){
                    client.onSoundComplete = function(){
                        if (iddiscussion<numberFile) {
                   iddiscussion = false;
                   trace("Add counter to "+iddiscussion);
                             delete client; //since we don't need it anymore
                   discussion();
                 }
                    }
                    trace("Client sound loaded, playing now.");
                    client.start();
                }else{
                    trace("Client Load Failed");
                }
            }
            client.loadSound(clientFile,true);
      }else if(serverCtr < numberFile){
          trace("Attaching next server sound.");
          server = new Sound(this);
          server.attachSound(serverAudio[serverCtr]);
          server.onSoundComplete = function(){
              trace("Server sound: "+serverAudio[serverCtr]+" finished playing.");
              serverCtr++;
              discussion();
          }
          server.start(0,0);
      }else {
         trace("Finished playing, deleting server soundObject");
         delete server;
      }
  }
}
  1. on (release) {
  2.   stopAllSounds();
  3.   var iddiscussion = 1; /*This needs to reflect the number in the name of the client sound, it will be assigned a value of "false" once client is done with. */
  4.   var numberFile = 3;
  5.   var serverCtr = 0;
  6.   var serverAudio = new Array("PE14_1a", "PE14_1c", "PE14_1e");
  7.   function discussion() {
  8.       if(iddiscussion){
  9.               clientFile = "file:///c:/program files/IEBAudioRecorder/test"+iddiscussion+".mp3";
  10.             client = new Sound(this);
  11.             client.onLoad = function(success){
  12.                 if(success){
  13.                     client.onSoundComplete = function(){
  14.                         if (iddiscussion<numberFile) {
  15.                    iddiscussion = false;
  16.                    trace("Add counter to "+iddiscussion);
  17.                              delete client; //since we don't need it anymore
  18.                    discussion();
  19.                  }
  20.                     }
  21.                     trace("Client sound loaded, playing now.");
  22.                     client.start();
  23.                 }else{
  24.                     trace("Client Load Failed");
  25.                 }
  26.             }
  27.             client.loadSound(clientFile,true);
  28.       }else if(serverCtr < numberFile){
  29.           trace("Attaching next server sound.");
  30.           server = new Sound(this);
  31.           server.attachSound(serverAudio[serverCtr]);
  32.           server.onSoundComplete = function(){
  33.               trace("Server sound: "+serverAudio[serverCtr]+" finished playing.");
  34.               serverCtr++;
  35.               discussion();
  36.           }
  37.           server.start(0,0);
  38.       }else {
  39.          trace("Finished playing, deleting server soundObject");
  40.          delete server;
  41.       }
  42.   }
  43. }
  • janice_2k
  • Novice
  • Novice
  • janice_2k
  • Posts: 28

Post 3+ Months Ago

Hi JoeBert,
Thanks for your reply. As you can see from my previous code, I played server side sound object 1st, then proceed to client side mp3, then loop back to server-client, server-client ...etc.

Currently, I want to load client side mp3 first, then load server side sound object. If there is no client side mp3 at the 1st place, it will continue playing sound object. This will loop until all client side mp3 and server side sound objects finishes. For example: Client1.mp3 - Server1, Client2.mp3 - Server2, Client3.mp3 - Server3 ... etc. If Client2.mp3 does not exist, it will continue to Server2, then Client3.mp3 - Server3...etc

I tried your code, there seems to have some errors.

Looking forward to your reply soon.

Thanks in advance,
Janice
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

In that case you can pull the actions for server.onSoundComplete() & create a function out of them, then swap the names of the functions around so that they call each other & have playClient() run first,

Code: [ Select ]
on (release) {
  stopAllSounds();
  var iddiscussion = 1;
  var numberFile = 5;
  var serverCtr = 0;
  var serverAudio = ["test1","test2","test3","test4","test5"];
  function playServer() {
   server = new Sound();
   serverFile = serverAudio[serverCtr];
   server.attachSound(serverFile);
   server.start(0, 0);
   trace("SERVER "+serverFile+iddiscussion);
   server.onSoundComplete = function() {
         if(iddiscussion < numberFile){
            playClient();
         }else{
             trace("Finished");
         }
   };
  };
  function playClient(){
   client = new Sound();
      clientFile = "file:///c:/test/s"+iddiscussion+".mp3";
      client.onLoad = function(success) {
      //define conditions for success first
      if (success) {
        this.start();
        client.onSoundComplete = function() {
        if (iddiscussion<=numberFile) {
          iddiscussion++;
          trace("Add counter to "+iddiscussion);
                playServer();
          serverCtr++;

        }
      };
     } else {
        //skip to the next file
        trace("SOUND FAILED!!!");
        if (iddiscussion<=numberFile) {
         iddiscussion++;
         trace("Add counter to "+iddiscussion);
         playServer();
         serverCtr++;
        }
      }
     };
     client.loadSound(clientFile, true);  
  }
  playClient();
}
  1. on (release) {
  2.   stopAllSounds();
  3.   var iddiscussion = 1;
  4.   var numberFile = 5;
  5.   var serverCtr = 0;
  6.   var serverAudio = ["test1","test2","test3","test4","test5"];
  7.   function playServer() {
  8.    server = new Sound();
  9.    serverFile = serverAudio[serverCtr];
  10.    server.attachSound(serverFile);
  11.    server.start(0, 0);
  12.    trace("SERVER "+serverFile+iddiscussion);
  13.    server.onSoundComplete = function() {
  14.          if(iddiscussion < numberFile){
  15.             playClient();
  16.          }else{
  17.              trace("Finished");
  18.          }
  19.    };
  20.   };
  21.   function playClient(){
  22.    client = new Sound();
  23.       clientFile = "file:///c:/test/s"+iddiscussion+".mp3";
  24.       client.onLoad = function(success) {
  25.       //define conditions for success first
  26.       if (success) {
  27.         this.start();
  28.         client.onSoundComplete = function() {
  29.         if (iddiscussion<=numberFile) {
  30.           iddiscussion++;
  31.           trace("Add counter to "+iddiscussion);
  32.                 playServer();
  33.           serverCtr++;
  34.         }
  35.       };
  36.      } else {
  37.         //skip to the next file
  38.         trace("SOUND FAILED!!!");
  39.         if (iddiscussion<=numberFile) {
  40.          iddiscussion++;
  41.          trace("Add counter to "+iddiscussion);
  42.          playServer();
  43.          serverCtr++;
  44.         }
  45.       }
  46.      };
  47.      client.loadSound(clientFile, true);  
  48.   }
  49.   playClient();
  50. }
  • janice_2k
  • Novice
  • Novice
  • janice_2k
  • Posts: 28

Post 3+ Months Ago

Hi JoeBert,
I tested the code. It seems to play:
Client1.mp3,
Server2 - Client2.mp3,
Server3 - Client3.mp3.

It has skipped the first server side sound object and on the 2nd looping, it returns back to playing server side sound object first, rather than client side.

I was hoping it to play:
Client1.mp3 - Server1,
Client2.mp3 - Server2,
Client3.mp3 - Server3 ... etc
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Theese two lines needed swapping,
Code: [ Select ]
serverCtr++;
playServer();
  1. serverCtr++;
  2. playServer();


It was incrementing the server count before playing the server file, causing the skip of ht efirst serverFile.

I've edited my previous post & swapped the two.
  • janice_2k
  • Novice
  • Novice
  • janice_2k
  • Posts: 28

Post 3+ Months Ago

Thanks Joebert,
I have noticed that after testing the amended code, the audio plays:

Client1.mp3 - Server1
Client2.mp3 - Server2
Client3

The last server side sound object -- 'Server3' went missing.

Besides, I noticed that when 1 of the client side mp3 file went missing, the functions seems to have error.

I removed Client2.mp3 from the client's computer. The audio I heard was:
Client1.mp3 - Server1
Server2
Client3.mp3

The 3rd sound object from server side -- Server3 seems to go missing. How should it be solved?

I was hoping that if one of the client side mp3 file does not exist, the audios will still continue playing. Example, if Client2.mp3 was missing, the audios played were:
Client1.mp3 - Server1
Server2
Client3.mp3 - Server3 ... etc

I apologize if I have troubled you so much. Hope to hear from you soon.

Thanks in advance,
Janice
  • janice_2k
  • Novice
  • Novice
  • janice_2k
  • Posts: 28

Post 3+ Months Ago

Hi Joebert,
I have edited part of the code you submitted earlier on. However, I have to change the variable "numberFile = 4" when I have 3 sound objects/audio files on server side. I also added an 'If-statement' in the playClient function, as it seems not to end the loop if I only change the numberFile = total number of audio files (numberFile = 3 when 3 sound objects)

The following is the code edited.
Code: [ Select ]
on (release) {
  stopAllSounds();
  var iddiscussion = 1;
  var numberFile = 4; //number of files + 1
  var serverCtr = 0;
  var serverAudio = new Array("PE14_1a", "PE14_1c", "PE14_1e");
  function playServer() {
   server = new Sound();
   serverFile = serverAudio[serverCtr];
   server.attachSound(serverFile);
   server.start(0, 0);
   trace("SERVER "+serverFile+iddiscussion);
   server.onSoundComplete = function() {
     playClient();
   };
  };
  function playClient(){
   if (iddiscussion<numberFile) {
        trace(iddiscussion+" < "+ numberFile);
   client = new Sound();
      clientFile = "file:///c:/program files/IEBAudioRecorder/test"+iddiscussion+".mp3";
      client.onLoad = function(success) {
      //define conditions for success first
      if (success) {
        this.start();
        trace("CLIENT "+clientFile+iddiscussion);
            client.onSoundComplete = function() {
        playServer(); //ADD
        if (iddiscussion<numberFile) {
          iddiscussion++;
          trace("Add counter to "+iddiscussion);
                //playServer();
          serverCtr++;
        }
      };
     } else {
        //skip to the next file
        trace("SOUND FAILED!!!");
              playServer(); //ADD
        if (iddiscussion<numberFile) {
         iddiscussion++;
         trace("Add counter to "+iddiscussion);
         //playServer();
         serverCtr++;
        }
      }
     };
     client.loadSound(clientFile, true);  
   };
  }
  playClient();
}
  1. on (release) {
  2.   stopAllSounds();
  3.   var iddiscussion = 1;
  4.   var numberFile = 4; //number of files + 1
  5.   var serverCtr = 0;
  6.   var serverAudio = new Array("PE14_1a", "PE14_1c", "PE14_1e");
  7.   function playServer() {
  8.    server = new Sound();
  9.    serverFile = serverAudio[serverCtr];
  10.    server.attachSound(serverFile);
  11.    server.start(0, 0);
  12.    trace("SERVER "+serverFile+iddiscussion);
  13.    server.onSoundComplete = function() {
  14.      playClient();
  15.    };
  16.   };
  17.   function playClient(){
  18.    if (iddiscussion<numberFile) {
  19.         trace(iddiscussion+" < "+ numberFile);
  20.    client = new Sound();
  21.       clientFile = "file:///c:/program files/IEBAudioRecorder/test"+iddiscussion+".mp3";
  22.       client.onLoad = function(success) {
  23.       //define conditions for success first
  24.       if (success) {
  25.         this.start();
  26.         trace("CLIENT "+clientFile+iddiscussion);
  27.             client.onSoundComplete = function() {
  28.         playServer(); //ADD
  29.         if (iddiscussion<numberFile) {
  30.           iddiscussion++;
  31.           trace("Add counter to "+iddiscussion);
  32.                 //playServer();
  33.           serverCtr++;
  34.         }
  35.       };
  36.      } else {
  37.         //skip to the next file
  38.         trace("SOUND FAILED!!!");
  39.               playServer(); //ADD
  40.         if (iddiscussion<numberFile) {
  41.          iddiscussion++;
  42.          trace("Add counter to "+iddiscussion);
  43.          //playServer();
  44.          serverCtr++;
  45.         }
  46.       }
  47.      };
  48.      client.loadSound(clientFile, true);  
  49.    };
  50.   }
  51.   playClient();
  52. }

Would be glad if you could guide/find any problems/not logical areas of the code. Hope to hear from you soon.

Thanks in advance,
Janice
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

I did the same edits, I put them in different spots though.

I changed server.onSoundComplete to,
Code: [ Select ]
server.onSoundComplete = function() {
         if(iddiscussion < numberFile){
            playClient();
         }else{
             trace("Finished");
         }
   };
  1. server.onSoundComplete = function() {
  2.          if(iddiscussion < numberFile){
  3.             playClient();
  4.          }else{
  5.              trace("Finished");
  6.          }
  7.    };


& updated the main if/else statements inside client.onLoad to,
Code: [ Select ]
if (iddiscussion<=numberFile) {


The < instead of <= was cutting it short, I caught/edited the endless loop while doing the <= . I added the if/else inside the server.onSoundComplete so that the event tests the statement instead of running the client function to do so.
  • janice_2k
  • Novice
  • Novice
  • janice_2k
  • Posts: 28

Post 3+ Months Ago

Hi JoeBert,
Thanks for the editing. Your method works fine too :)

I have another inquery, what if there is one extra server side sound object which has no client side mp3 to be paired with? In other words, that I don't intend to change its name in the Array(like the ones I have on my previous codes) ? Example, I want the button to play:

ServerExtra,
Server1 - Client1.mp3,
Server2 - Client2.mp3,
Server3 - Client3.mp3 ... etc

How should I amend the code? The following is the code I used to play server/client audio files
Code: [ Select ]
on (release) {
    stopAllSounds();
    var iddiscussion = 1;
    var numberFile = 3;
    var serverCtr = 0;
    var serverAudio = new Array("PE14_1a", "PE14_1c", "PE14_1e");
    function discussion() {
        server = new Sound();
        //serverFile = "PE14_1d";
        serverFile = serverAudio[serverCtr];
        server.attachSound(serverFile);
        //server side mp3
        server.start(0, 0);
        trace("SERVER "+serverFile+iddiscussion);
        server.onSoundComplete = function() {
            client = new Sound();
            clientFile = "file:///c:/program files/IEBAudioRecorder/test"+iddiscussion+".mp3";
            client.onLoad = function(success) {
                //define conditions for success first
                if (success) {
                    this.start();
                    trace("SOUND SUCCESS!!!");
                    client.onSoundComplete = function() {
                        //doesn't run if not success...
                        if (iddiscussion<numberFile) {
                            //no longer dependent on client.onSoundComplete
                            iddiscussion++;
                            trace("Add counter to "+iddiscussion);
                            serverCtr++;
                            discussion();
                        }
                    };
                } else {
                    //skip to the next file
                    trace("SOUND FAILED!!!");
                    if (iddiscussion<numberFile) {
                        //no longer dependent on client.onSoundComplete
                        iddiscussion++;
                        trace("Add counter to "+iddiscussion);
                        serverCtr++;
                        discussion();
                    }
                }
            };
            client.loadSound(clientFile, true);
            //load client mp3
            trace("CLIENT "+clientFile+iddiscussion);
        };
    }
    discussion();
}
  1. on (release) {
  2.     stopAllSounds();
  3.     var iddiscussion = 1;
  4.     var numberFile = 3;
  5.     var serverCtr = 0;
  6.     var serverAudio = new Array("PE14_1a", "PE14_1c", "PE14_1e");
  7.     function discussion() {
  8.         server = new Sound();
  9.         //serverFile = "PE14_1d";
  10.         serverFile = serverAudio[serverCtr];
  11.         server.attachSound(serverFile);
  12.         //server side mp3
  13.         server.start(0, 0);
  14.         trace("SERVER "+serverFile+iddiscussion);
  15.         server.onSoundComplete = function() {
  16.             client = new Sound();
  17.             clientFile = "file:///c:/program files/IEBAudioRecorder/test"+iddiscussion+".mp3";
  18.             client.onLoad = function(success) {
  19.                 //define conditions for success first
  20.                 if (success) {
  21.                     this.start();
  22.                     trace("SOUND SUCCESS!!!");
  23.                     client.onSoundComplete = function() {
  24.                         //doesn't run if not success...
  25.                         if (iddiscussion<numberFile) {
  26.                             //no longer dependent on client.onSoundComplete
  27.                             iddiscussion++;
  28.                             trace("Add counter to "+iddiscussion);
  29.                             serverCtr++;
  30.                             discussion();
  31.                         }
  32.                     };
  33.                 } else {
  34.                     //skip to the next file
  35.                     trace("SOUND FAILED!!!");
  36.                     if (iddiscussion<numberFile) {
  37.                         //no longer dependent on client.onSoundComplete
  38.                         iddiscussion++;
  39.                         trace("Add counter to "+iddiscussion);
  40.                         serverCtr++;
  41.                         discussion();
  42.                     }
  43.                 }
  44.             };
  45.             client.loadSound(clientFile, true);
  46.             //load client mp3
  47.             trace("CLIENT "+clientFile+iddiscussion);
  48.         };
  49.     }
  50.     discussion();
  51. }


Looking forward to your reply soon.

Thanks in advance,
Janice
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

So... server0, server1, client1, server2, client2, ect.. ?

Easiest way would be to wrap the initiating call to discussion() inside an onSoundComplete for the extra server sound.

Skipping to the end,
Code: [ Select ]
    };
     client.loadSound(clientFile, true);
     //load client mp3
     trace("CLIENT "+clientFile+iddiscussion);
   };
  }
extraServer = new Sound();
extraServer.attachSound("extraSoundLinkageId");
extraServer.onSoundComplete = function(){
  discussion();
  delete extraServer;
}
extraServer.start(0,0);
}
  1.     };
  2.      client.loadSound(clientFile, true);
  3.      //load client mp3
  4.      trace("CLIENT "+clientFile+iddiscussion);
  5.    };
  6.   }
  7. extraServer = new Sound();
  8. extraServer.attachSound("extraSoundLinkageId");
  9. extraServer.onSoundComplete = function(){
  10.   discussion();
  11.   delete extraServer;
  12. }
  13. extraServer.start(0,0);
  14. }
  • janice_2k
  • Novice
  • Novice
  • janice_2k
  • Posts: 28

Post 3+ Months Ago

Sorry Joebert,
It seems not to work at all.

By the way, the extra sound object will not have the same format of file name as the ones we have. The file name might be ServerExtra instead of Server0
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

You have to make sure that the sound is linked for export like the other server sounds in the library.
Heres the full edit,
Code: [ Select ]
on (release) {
  stopAllSounds();
  var iddiscussion = 1;
  var numberFile = 3;
  var serverCtr = 0;
  var serverAudio = new Array("PE14_1a", "PE14_1c", "PE14_1e");
  function discussion() {
   server = new Sound();
   //serverFile = "PE14_1d";
   serverFile = serverAudio[serverCtr];
   server.attachSound(serverFile);
   //server side mp3
   server.start(0, 0);
   trace("SERVER "+serverFile+iddiscussion);
   server.onSoundComplete = function() {
     client = new Sound();
     clientFile = "file:///c:/program files/IEBAudioRecorder/test"+iddiscussion+".mp3";
     client.onLoad = function(success) {
      //define conditions for success first
      if (success) {
        this.start();
        trace("SOUND SUCCESS!!!");
        client.onSoundComplete = function() {
         //doesn't run if not success...
         if (iddiscussion<numberFile) {
           //no longer dependent on client.onSoundComplete
           iddiscussion++;
           trace("Add counter to "+iddiscussion);
           serverCtr++;
           discussion();
         }
        };
      } else {
        //skip to the next file
        trace("SOUND FAILED!!!");
        if (iddiscussion<numberFile) {
         //no longer dependent on client.onSoundComplete
         iddiscussion++;
         trace("Add counter to "+iddiscussion);
         serverCtr++;
         discussion();
        }
      }
     };
     client.loadSound(clientFile, true);
     //load client mp3
     trace("CLIENT "+clientFile+iddiscussion);
   };
  }
/*--------revised from here---------*/
extraSound = new Sound();
extraSound.attachSound("serverExtra"); /*make sure the name you give in linkage goes here inside the quotes*/
extraSound.onSoundComplete = function(){
  discussion();
  delete extraSound;
}
extraSound.start(0,0);
}
  1. on (release) {
  2.   stopAllSounds();
  3.   var iddiscussion = 1;
  4.   var numberFile = 3;
  5.   var serverCtr = 0;
  6.   var serverAudio = new Array("PE14_1a", "PE14_1c", "PE14_1e");
  7.   function discussion() {
  8.    server = new Sound();
  9.    //serverFile = "PE14_1d";
  10.    serverFile = serverAudio[serverCtr];
  11.    server.attachSound(serverFile);
  12.    //server side mp3
  13.    server.start(0, 0);
  14.    trace("SERVER "+serverFile+iddiscussion);
  15.    server.onSoundComplete = function() {
  16.      client = new Sound();
  17.      clientFile = "file:///c:/program files/IEBAudioRecorder/test"+iddiscussion+".mp3";
  18.      client.onLoad = function(success) {
  19.       //define conditions for success first
  20.       if (success) {
  21.         this.start();
  22.         trace("SOUND SUCCESS!!!");
  23.         client.onSoundComplete = function() {
  24.          //doesn't run if not success...
  25.          if (iddiscussion<numberFile) {
  26.            //no longer dependent on client.onSoundComplete
  27.            iddiscussion++;
  28.            trace("Add counter to "+iddiscussion);
  29.            serverCtr++;
  30.            discussion();
  31.          }
  32.         };
  33.       } else {
  34.         //skip to the next file
  35.         trace("SOUND FAILED!!!");
  36.         if (iddiscussion<numberFile) {
  37.          //no longer dependent on client.onSoundComplete
  38.          iddiscussion++;
  39.          trace("Add counter to "+iddiscussion);
  40.          serverCtr++;
  41.          discussion();
  42.         }
  43.       }
  44.      };
  45.      client.loadSound(clientFile, true);
  46.      //load client mp3
  47.      trace("CLIENT "+clientFile+iddiscussion);
  48.    };
  49.   }
  50. /*--------revised from here---------*/
  51. extraSound = new Sound();
  52. extraSound.attachSound("serverExtra"); /*make sure the name you give in linkage goes here inside the quotes*/
  53. extraSound.onSoundComplete = function(){
  54.   discussion();
  55.   delete extraSound;
  56. }
  57. extraSound.start(0,0);
  58. }


This worked fine for me.
  • janice_2k
  • Novice
  • Novice
  • janice_2k
  • Posts: 28

Post 3+ Months Ago

Hi Joebert,
Thanks for your guide and codes. I found the error on my sound object already. I didn't notice the sound object's name was "ExtraServer " with a space bar behind. Anyway, thank you so much for helping me. I really appreciate that. Should I have any other programming matters in near future, I would be very glad if you could also guide me. Have a nice day.

PS: Can we keep in touch by other means like msgr/icq?

Thank you
Janice
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 30 posts
  • Users browsing this forum: No registered users and 9 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.