Can Actionscript load client side .wav files?

  • janice_2k
  • Novice
  • Novice
  • No Avatar
  • Joined: Jun 03, 2004
  • Posts: 28
  • Status: Offline

Post June 20th, 2004, 11:39 pm

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
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post June 20th, 2004, 11:39 pm

  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Joined: Jun 26, 2003
  • Posts: 1402
  • Loc: Philadelphia, PA
  • Status: Offline

Post June 23rd, 2004, 10:12 am

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

Post June 23rd, 2004, 9:32 pm

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
  • Joined: Jun 26, 2003
  • Posts: 1402
  • Loc: Philadelphia, PA
  • Status: Offline

Post June 23rd, 2004, 10:21 pm

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
  • No Avatar
  • Joined: Jul 02, 2004
  • Posts: 6
  • Loc: Malaysia
  • Status: Offline

Post July 4th, 2004, 10:15 pm

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
  • No Avatar
  • Joined: Jul 05, 2004
  • Posts: 1
  • Loc: Wisconsin, USA
  • Status: Offline

Post July 5th, 2004, 4:46 pm

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
  • No Avatar
  • Joined: Jul 02, 2004
  • Posts: 6
  • Loc: Malaysia
  • Status: Offline

Post July 6th, 2004, 3:24 am

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
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post July 8th, 2004, 9:19 am

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
Strong with this one, the sudo is.
  • janice_2k
  • Novice
  • Novice
  • No Avatar
  • Joined: Jun 03, 2004
  • Posts: 28
  • Status: Offline

Post July 12th, 2004, 1:00 am

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
  • No Avatar
  • Joined: Jun 03, 2004
  • Posts: 28
  • Status: Offline

Post July 12th, 2004, 1:10 am

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
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post July 12th, 2004, 9:02 am

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.
Strong with this one, the sudo is.
  • janice_2k
  • Novice
  • Novice
  • No Avatar
  • Joined: Jun 03, 2004
  • Posts: 28
  • Status: Offline

Post July 14th, 2004, 1:32 am

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
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post July 14th, 2004, 9:22 am

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)
Strong with this one, the sudo is.
  • janice_2k
  • Novice
  • Novice
  • No Avatar
  • Joined: Jun 03, 2004
  • Posts: 28
  • Status: Offline

Post July 15th, 2004, 6:51 pm

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
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post July 15th, 2004, 7:25 pm

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.
Strong with this one, the sudo is.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post July 15th, 2004, 7:25 pm

Post Information

  • Total Posts in this topic: 30 posts
  • Users browsing this forum: No registered users and 74 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
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.