我有一个按钮,它将文本字段的值更改为0或100(反之亦然)。文本字段调用函数CheckSound
function CheckSound():void
{
if(options_mc.onoff_txt.text == "100")
{
tchannel = theme.play(0,9999);
}
else if(options_mc.onoff_txt.text == "0")
{
tchannel.stop();
}
}
声音停止并播放。当我去游戏中的另一个场景时,tchannel停止播放并且rchannel开始播放。这就是我要的。我的问题是如果值为0,我怎么能停止tchannel和rchannel。如果值为100,我怎样才能让tchannel和rchannel在他们的右边框架上播放?
答案 0 :(得分:0)
您可以依赖当前场景名称来决定播放哪种声音。
import flash.display.Scene;
// ...
function CheckSound():void
{
if (options_mc.onoff_txt.text == "100")
{
playCurSceneSound();
}
else if (options_mc.onoff_txt.text == "0")
{
stopMySounds();
}
}
function stopMySounds():void
{
tchannel.stop();
rchannel.stop();
}
function playCurSceneSound():void
{
var curScene:Scene = this.currentScene;
trace("We are in scene: "+curScene.name);
// use the Scene name to choose the suitable sound for this scene:
switch (curScene.name)
{
case "Scene 1" :
tchannel = theme.play(0,9999);
break;
case "Scene 2" :
rchannel = rheme.play(0,9999);
break;
default :
trace("No sound for '"+ curScene.name + "' scene! ");
break;
}
}