我使用Flash AS3为声音创建了一个开/关按钮。这些工作,但每当我按下关闭按钮,然后按下开启按钮,音乐不会再播放?
我认为这是一个循环问题,但我可能错了吗?如果它是一个循环问题,我不确定要使用什么代码。
我还需要为btnOn函数添加代码,因为当我打开.swf时,声音会自动播放。
附件是我目前的代码:
change(input_file_name, output_file_name, pid1, pid1_file_name, pid2, pid2_file_name, etc... );
干杯:)
答案 0 :(得分:0)
您的代码仅显示事件监听器onClickPause(我认为这是您的停止按钮)。但是开始/播放按钮的事件监听器在哪里。在播放按钮上,您必须再次调用播放功能。这是一个很棒的教程:http://www.republicofcode.com/tutorials/flash/as3sound/
答案 1 :(得分:0)
您可以尝试以下代码。它使用一个按钮进行音频暂停/恢复功能...
var mySound:Sound = new sandstorm(); //(sandstorm is my sound file)
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;
var audioState : String = "paused"; //will become either "playing" or "paused"
myChannel = mySound.play(); //this line starts playback
audioState = "playing"; //update because you started playback with above line
btnOff.addEventListener(MouseEvent.CLICK, onPlayPause);
function onPlayPause(e:MouseEvent):void
{
if (audioState == "playing") //IF already playing
{
lastPosition = myChannel.position; //note current "audio time" when pausing
myChannel.stop(); //stop playback
audioState = "paused"; //update for next time click is used
}
else if (audioState == "paused") //or ELSE IF was already paused then...
{
myChannel = mySound.play(lastPosition); //resume playback
audioState = "playing"; //update for next time click is used
}
}