Skip to main content
July 17, 2009
Question

Error trapping a sound file

  • July 17, 2009
  • 2 replies
  • 680 views

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

This topic has been closed for replies.

2 replies

July 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.

kglad
Community Expert
Community Expert
July 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?

July 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

kglad
Community Expert
Community Expert
July 17, 2009

show your onLoad code that you think fails.