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

Error trapping a sound file

Guest
Jul 17, 2009 Jul 17, 2009

Hi all

Is it at all possible to test if a sound file has not been found? Every tutorial I have read regarding sound.loadSound and sound.onLoad has been focused on everything being fine and flash finding the correct file. I need to be able to get a flash movie to continue as normal if the sound file is unavailable.

For example:

My flash movie loads in a sound then waits for the sound to finish before continuing using the sound.onSoundComplete event. This wont work if the sound is not present, and so the movie stops and does nothing. I have tried to use sound.onLoad if (success == false) but flash seems to go here before it even starts loading the sound file, making my movie believe that no flash file is loading even though one is.

Any help on this matter would be most grateful, a workaround would be even better

cheers

Ash

TOPICS
ActionScript
647
Translate
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
Community Expert ,
Jul 17, 2009 Jul 17, 2009

show your onLoad code that you think fails.

Translate
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
Guest
Jul 18, 2009 Jul 18, 2009

Here is the code I am using:

the variables soundAvail, point and endPoint are declared on another frame.

var speech:Sound = new Sound(this);
speech.onLoad = function(success:Boolean) {
if (success) {
speech.start(0,0);
soundAvail = true;
}
if (success == false){
soundAvail = false;
}
};

speech.loadSound("lesson2audio/02_00.mp3",false);

here are the functions that control the movie:

speech.onSoundComplete = function() {
if (point == endPoint) {
gotoAndPlay("end");
} else {
gotoAndPlay("point"+point);
point++;
}
};
function soundCheck():Void {
if (soundAvail == false) {
if (point == endPoint) {
gotoAndPlay("end");
} else {
gotoAndPlay("point"+point);
point++;
}
}
}

soundCheck(); on the stop frame is called after all the animations are finished.

At the moment all of this code does work apart from:

if (success == false){
soundAvail = false;
}

which is called way to quickly.

Translate
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
Community Expert ,
Jul 18, 2009 Jul 18, 2009

create a new fla that contains:

var speech:Sound = new Sound(this);
speech.onLoad = function(success:Boolean) {
if (success) {
speech.start(0,0);
soundAvail = true;
}
if (success == false){
soundAvail = false;
}
};

speech.loadSound("lesson2audio/02_00.mp3",false);

do you see any problem?

Translate
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
Guest
Jul 18, 2009 Jul 18, 2009

Hi kglad

The only thing I can think of that could be wrong with it is that flash is going to have to keep checking the onLoad call to see if the whole file has loaded, hence why it keeps saying its not loaded before it has. Do you think I should use bytes loaded and bytes total instead, at least then I would be able to tell if the file has started to load or not?

Ash

Translate
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
Community Expert ,
Jul 18, 2009 Jul 18, 2009

i don't see any problem.  you must be doing something to cause a problem.

did you use the code i supplied above in a new fla?  was there a problem?  if yes and yes, post a link to your new fla.

Translate
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
Guest
Jul 19, 2009 Jul 19, 2009

Ok when you load the file through a fast net connection or via flash then yes it does indeed pick up in time if the file is there or not. Which makes the code I posted absolutly fine. The problem arises when I use the download simulator to simulate a slow connection. I used the code you posted above, added some trace statements for each outcome and then tested it using the download simulator set at 32.6 KB/s. Flash does go to the failed section before it reaches the loaded one. Which has a knock on effect of changing all my variables to false and skips all my audio. I do appriciate the time you have spent so far.

Cheers

Ash

Translate
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
Community Expert ,
Jul 19, 2009 Jul 19, 2009
LATEST

you're welcome.

Translate
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