简体   繁体   English

声音在as3中重叠

[英]Overlapping sound in as3

Okay, so I am making a game, and I can't figure out how to keep the sound track from overlapping. 好吧,所以我在做游戏,我不知道如何避免音轨重叠。 When the game comes to a lose or win screen, I will click "Play again" and the sound will overlap. 当游戏进入输赢屏幕时,我将单击“再次玩”,声音将重叠。 I have the sound on it's own layer. 我在自己的图层上有声音。 Here's what I have so far. 到目前为止,这就是我所拥有的。

var snd_SolidState = new SolidState();
snd_SolidState.play(0,1);

And on Layer 2 Frame 2 and 3, I have: 在第2层第2帧和第3帧上,我有:

snd_SolidState.stop();
snd_SolidState = null;

It says "stop" is not a function. 它说“停止”不是功能。 So how would I get the song to stop on the lose/win screens? 那么我如何让歌曲在输赢屏幕上停止播放? SolidState is the song. SolidState是歌曲。

If the code is related to the click of the "Play again" Button, here is the code for those. 如果代码与单击“再次播放”按钮有关,则为这些代码。

mc_again.addEventListener(MouseEvent.MOUSE_UP,upAgain);
function upAgain(e:MouseEvent){
gotoAndStop(1);
}

Can anyone help? 有人可以帮忙吗?

You need to use a SoundChannel to stop your music. 您需要使用SoundChannel停止音乐。 check out this tutorial. 查看本教程。

http://www.republicofcode.com/tutorials/flash/as3sound/ http://www.republicofcode.com/tutorials/flash/as3sound/

The variable snd_SolidState is a Sound object, Sound doesn't have a stop method implemented; 变量snd_SolidState是一个Sound对象, Sound没有实现stop方法。 The Sound .play() however, returns a SoundChannel object which does... Sound .play()但是会返回一个SoundChannel对象,该对象不会...

So you can store that (the SoundChannel object returned by snd_SolidState.play() ), which you can later use to stop the song. 因此,您可以存储它( snd_SolidState.play()返回的SoundChannel对象),以后可以用来停止播放歌曲。

PS: I recommend you start typing your variables (ie: var snd_SolidState:Sound; ), that way you force yourself to know which object type you're dealing with and can find reference for it; PS:我建议您开始键入变量(即var snd_SolidState:Sound; ),这样您就可以迫使自己知道要处理的对象类型并可以找到它的引用。 in this case Sound.play() . 在这种情况下, Sound.play()

Good luck :) 祝好运 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM