Skip navigation
DKostrzewa
Currently Being Moderated

Occasional no sound when trying to play sound.

Apr 29, 2012 7:35 AM

Tags: #flash #no_sound #actionscript #2.0

Hi all,

 

I am having a problem where sometimes there is no sound when I try to play an mp3 file from within a SWF I have created in CS3 Professional.

 

By sometimes I mean 1 time out of 10, sometimes more or less frequently.

 

I have a button btnPlay whose onClick event starts the sound playing. It works most of the time, but occasionally there is no sound at all. Refreshing the page and reloading the flash does help sometimes but not always.

 

Due to the nature of the application we don't allow users to replay the sound nor to refresh the page so it is very important to play the sound properly every time.

 

The code is below:

 

var sound:Sound = null;

btnPlay.enabled=false;
btnPlay._alpha=25;

sound=new Sound(this);
sound.onLoad=function(success){
  if (success) {
    sound.setVolume(100);
    btnPlay.enabled=true;
    btnPlay._alpha=100;
  } 
  else {
    btnPlay._alpha = 0;
  }
}

sound.onSoundComplete=function(){
  if(allowReplay){
    btnPlay.enabled=true;
    btnPlay._alpha=100;
    sound.stop();
   }
}

btnPlay.onPress=function(){
  sound.start(0, 1);
  btnPlay.enabled=false;
  btnPlay._alpha=25;
}

Stage.addListener(this);
Stage.align=("TL");
function onResize(){
  btnPlay._x=(Stage.width/2)-(btnPlay._width/2);
}
onResize();
sound.loadSound(MediaUrl, false);

 

Also because we’re greying out the button when play starts and showing it normally when the sound is complete, we can actually see how long the sound is supposed to be playing for, even if we hear no sound. In these cases it still shows greyed out for the right amount of time we’re expecting that sound file to play for.

 

I’ve googled but can't find anything that says there is a known problem, nor can I see any problem in my code since the sound is successfully requested and loaded every time – i.e. the sound.onLoad event handler is always successful.

 

We use this component in a couple of SWFs and on a set of different web pages and the problem still occurs.

 

Does anyone has any suggestions or could give me directions how to solve this problem?

 
Replies
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 29, 2012 8:36 AM   in reply to DKostrzewa

    use the trace function to make sure that code only executes once and fix your loop parameter so you sound doesn't loop.

     
    |
    Mark as:
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 30, 2012 7:28 AM   in reply to DKostrzewa

    there's nothing in the code you showed that would cause that problem.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points