展开菜单(影片剪辑)和音乐设置错误中的音乐

Expand menu (movieclip) and music in music setting error

我在Flash中做了一个可以展开的菜单,里面有音乐设置。

应用程序启动时播放音乐。要停止播放音乐,您必须展开菜单并单击音乐图标。

但之后出现了问题:
音乐又停不下来,背景音乐加倍播放。

这是我的 FLA 文件:

https://drive.google.com/file/d/1DpqdH64kDnI8xN6fBAt3pwi_bIRQ52mT/view?usp=drivesdk

谁能告诉我我程序的错误?谢谢

关于 "music playing double" 您的(音频)播放功能是否创建了 new 任何内容?
(例如:= new Sound= new SoundChannel)?如果是...

  • 在函数之外创建音频变量,然后将函数仅用于 stop/start 音频播放。

  • 仅在加载新曲目时使用new Sound,加载后使用SoundChannel至play/stop Sound对象。

  • 您需要一个 Boolean 来跟踪 Sound 是否已经在播放。如果 true 则不要发送另一个 .play() 命令(现在给 output/speakers 两个声音)。

看看下面的代码逻辑是否能指导您进行更好的设置:

//# declare variables globally (not trapped inside some function)
var snd_Obj :Sound;
var snd_Chann :SoundChannel = new SoundChannel();

var snd_isPlaying :Boolean = false;

//# main app code
loadTrack("someSong.mp3"); //run a function, using "filename" as input parameter


//# supporting functions
function loadTrack (input_filename :String) : void 
{ 
    snd_Obj = new Sound(); 
    snd_Obj.addEventListener(Event.COMPLETE, finished_LoadTrack);
    snd_Obj.load( input_filename ); //read from function's input parameter
}

function finished_LoadTrack (event:Event) : void 
{ 
    snd_Chann = snd_Obj.play(); //# Play returned Speech convert result
    snd_Obj.removeEventListener(Event.COMPLETE, onSoundLoaded);

    //# now make your Play and Stop buttons active
    btn_play.addEventListener(MouseEvent.CLICK, play_Track);
    btn_stop.addEventListener(MouseEvent.CLICK, stop_Track);

}

function play_Track (event:Event) : void 
{ 
    //# responds to click of Play button 

    if(snd_isPlaying != true) //# check if NOT TRUE, only then start playback
    { 
        snd_Chann = snd_Obj.play(); 
        snd_isPlaying = true; //# now set TRUE to avoid multiple "Play" commands at once
    }
}

function stop_Track (event:Event) : void 
{
    //# responds to click of Play button 
    snd_Chann.stop();
    snd_isPlaying = false; //# now set FALSE to reset for next Play check
}