Sunday, January 4, 2009

Solve the problem of sound on/of button in flash(Wk11_2)

In my previous flashes assignments I countered a problem is that when replaying the sound again and again. This problem happens when the previous sound is still playing. So, I suggest a solution:

In the replay button we add this code:

on(release)
{

stopAllSounds();
gotoAndPlay(1);

}


In the first frame of timeline add this code :

firstSound=new Sound();
firstSound.attachSound("main");
firstSound.start(0,999);

"main" is the name of linkage of sound imported in the library.

In the "on" button of sound we add this code:

on (release) {

_root.firstSound.setVolume (0);
this.gotoAndStop("off");
}

In the "off" button of sound we add this code:

on (release) {

_root.firstSound.setVolume(100);



this.gotoAndStop("on");

}

This is the most simple way to solve the problem when the sound play again and again at the same time.

No comments: